-
-
Notifications
You must be signed in to change notification settings - Fork 71
refactor: add support for epoch seconds #2253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ public static List<LetterSoundLearningEvent> extractLetterSoundLearningEvents(Fi | |
| // https://github.com/elimu-ai/analytics/releases/tag/3.4.0 | ||
| timestampColumnName = "timestamp"; | ||
| } | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName)); | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName).substring(0, 10)) * 1_000; | ||
| Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); | ||
| timestamp.setTimeInMillis(timestampInMillis); | ||
| letterSoundLearningEvent.setTimestamp(timestamp); | ||
|
Comment on lines
+127
to
130
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Guard against short or malformed timestamp strings & remove duplication Each extractor now does long ts = Long.valueOf(csvRecord.get(col).substring(0, 10)) * 1_000;Issues:
Proposed refactor (utility method + bounds check): + private static Calendar toUtcCalendarFromEpochSeconds(String raw) {
+ if (raw == null || raw.length() < 10) {
+ throw new IllegalArgumentException("Invalid epoch string: " + raw);
+ }
+ long millis = Long.parseLong(raw.substring(0, 10)) * 1_000L;
+ Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ cal.setTimeInMillis(millis);
+ return cal;
+ }Then replace every block with: - long timestampInMillis = Long.valueOf(csvRecord.get(col).substring(0, 10)) * 1_000;
- Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- timestamp.setTimeInMillis(timestampInMillis);
+ Calendar timestamp = toUtcCalendarFromEpochSeconds(csvRecord.get(col));This removes repetition and makes failures explicit. Also applies to: 174-177, 240-243, 306-309, 369-372, 430-433 🤖 Prompt for AI Agents |
||
|
|
@@ -171,7 +171,7 @@ public static List<NumberLearningEvent> extractNumberLearningEvents(File csvFile | |
|
|
||
| NumberLearningEvent numberLearningEvent = new NumberLearningEvent(); | ||
|
|
||
| long timestampInMillis = Long.valueOf(csvRecord.get("timestamp")); | ||
| long timestampInMillis = Long.valueOf(csvRecord.get("timestamp").substring(0, 10)) * 1_000; | ||
| Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); | ||
| timestamp.setTimeInMillis(timestampInMillis); | ||
| numberLearningEvent.setTimestamp(timestamp); | ||
|
|
@@ -237,7 +237,7 @@ public static List<WordAssessmentEvent> extractWordAssessmentEvents(File csvFile | |
| // https://github.com/elimu-ai/analytics/releases/tag/3.4.0 | ||
| timestampColumnName = "timestamp"; | ||
| } | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName)); | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName).substring(0, 10)) * 1_000; | ||
| Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); | ||
| timestamp.setTimeInMillis(timestampInMillis); | ||
| wordAssessmentEvent.setTimestamp(timestamp); | ||
|
|
@@ -303,7 +303,7 @@ public static List<WordLearningEvent> extractWordLearningEvents(File csvFile) { | |
| // https://github.com/elimu-ai/analytics/releases/tag/3.4.0 | ||
| timestampColumnName = "timestamp"; | ||
| } | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName)); | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName).substring(0, 10)) * 1_000; | ||
| Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); | ||
| timestamp.setTimeInMillis(timestampInMillis); | ||
| wordLearningEvent.setTimestamp(timestamp); | ||
|
|
@@ -366,7 +366,7 @@ public static List<StoryBookLearningEvent> extractStoryBookLearningEvents(File c | |
| // https://github.com/elimu-ai/analytics/releases/tag/3.4.0 | ||
| timestampColumnName = "timestamp"; | ||
| } | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName)); | ||
| long timestampInMillis = Long.valueOf(csvRecord.get(timestampColumnName).substring(0, 10)) * 1_000; | ||
| Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); | ||
| timestamp.setTimeInMillis(timestampInMillis); | ||
| storyBookLearningEvent.setTimestamp(timestamp); | ||
|
|
@@ -427,7 +427,7 @@ public static List<VideoLearningEvent> extractVideoLearningEvents(File csvFile) | |
|
|
||
| VideoLearningEvent videoLearningEvent = new VideoLearningEvent(); | ||
|
|
||
| long timestampInMillis = Long.valueOf(csvRecord.get("timestamp")); | ||
| long timestampInMillis = Long.valueOf(csvRecord.get("timestamp").substring(0, 10)) * 1_000; | ||
| Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); | ||
| timestamp.setTimeInMillis(timestampInMillis); | ||
| videoLearningEvent.setTimestamp(timestamp); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.