HeX0R hat geschrieben:
Zu 1: Nein, sonst hätte ich geschrieben ich habe 3 Felder: Tag / timestamp / Float.
Es ist ein typischer Timestamp, also Sekunden seit 1.1.1970 (in diesem Fall sogar ms) und beinhaltet natürlich auch Jahr/Monat/Tag
Naja, unter Timestamp versteht man viele Schreibweisen ("01:00" ist ebenso ein Timestamp), weshalb die Frage, ob die Tagesangabe zum Timestamp dazugehört durchaus berechtigt ist.
Eine wichtige Information, die du nun genannt hast, ist, dass der Timestamp ein Unix-Timestamp - jedoch in Millisekunden - ist.
HeX0R hat geschrieben:
Ansatz 2:
[...]wobei mich interessieren grundsätzlich immer nur 7 Tage!
Ebenfalls eine wichtige Information, die zuvor unbekannt war.
Die Frage ist nun, welche 7 Tage - die letzten der Datenbank?
Ich habe dir schnell ein Code geschrieben:
Code:
UseSQLiteDatabase()
Filename$ = GetTemporaryDirectory() + "Test.sqlite"
If CreateFile(0, Filename$)
Debug "Database file created"
CloseFile(0)
EndIf
If OpenDatabase(0, Filename$, "", "")
Debug "Connected to Test.sqlite"
If DatabaseUpdate(0, "CREATE TABLE info (timestamp TEXT, floatnumber REAL);")
Debug "Table created"
EndIf
EndIf
Debug "----------"
Date = Date()
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 1, 0, 1, 0) * 1000) + "', '0.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 1, 1, 0, 0) * 1000) + "', '0.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 1, 12, 0, 0) * 1000) + "', '1.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 1, 23, 59, 0) * 1000) + "', '1.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 2, 5, 0, 0) * 1000) + "', '2.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 2, 11, 0, 0) * 1000) + "', '3.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 2, 16, 0, 0) * 1000) + "', '4.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 2, 23, 59, 0) * 1000) + "', '6.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 3, 1, 0, 0) * 1000) + "', '7.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 4, 0, 1, 0) * 1000) + "', '7.1');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 4, 1, 0, 0) * 1000) + "', '7.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 5, 12, 0, 0) * 1000) + "', '8.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 5, 23, 59, 0) * 1000) + "', '8.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 6, 5, 0, 0) * 1000) + "', '9.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 7, 11, 0, 0) * 1000) + "', '9.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 8, 16, 0, 0) * 1000) + "', '10.5');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 9, 23, 59, 0) * 1000) + "', '11.0');")
Debug DatabaseUpdate(0, "INSERT INTO info VALUES ('" + Str(Date(Year(Date), Month(Date), 10, 1, 0, 0) * 1000) + "', '12.0');")
Debug "----------"
If DatabaseQuery(0, "SELECT STRFTIME('%j',DATETIME(timestamp/1000,'unixepoch')) AS days, floatnumber FROM info GROUP BY days LIMIT 7")
If NextDatabaseRow(0)
Day = GetDatabaseLong(0, 0)
Debug "Tag 1 ----- " + GetDatabaseString(0, 1)
While NextDatabaseRow(0)
Debug "Tag " + Str(GetDatabaseLong(0, 0) - Day + 1) + " ----- " + GetDatabaseString(0, 1)
Wend
EndIf
EndIf
CloseDatabase(0)
Debug-Ausgabe:
Code:
[16:35:17] Database file created
[16:35:17] Connected to Test.sqlite
[16:35:17] Table created
[16:35:17] ----------
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] 1
[16:35:17] ----------
[16:35:17] Tag 1 ----- 1.5
[16:35:17] Tag 2 ----- 6.0
[16:35:17] Tag 3 ----- 7.0
[16:35:17] Tag 4 ----- 7.5
[16:35:17] Tag 5 ----- 8.5
[16:35:17] Tag 6 ----- 9.0
[16:35:17] Tag 7 ----- 9.5