Skip to content

Commit

Permalink
Merge pull request #106 from Carifio24/advanced-weather-time
Browse files Browse the repository at this point in the history
Advanced weather time
  • Loading branch information
Carifio24 authored Mar 14, 2024
2 parents a4697d2 + 4ddebfe commit 82e7b36
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/stories/solar-eclipse-2024/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ export const SolarEclipse2024Entry = S.struct({
cloud_cover_selected_locations: LatLonArray,
info_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
app_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
advanced_weather_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
});

export const SolarEclipse2024Update = S.struct({
user_selected_locations: S.optional(LatLonArray, { exact: true }),
cloud_cover_selected_locations: S.optional(LatLonArray, { exact: true }),
delta_info_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
delta_app_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
delta_advanced_weather_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
});

export type SolarEclipse2024DataT = S.Schema.To<typeof SolarEclipse2024Entry>;
Expand Down Expand Up @@ -73,6 +75,9 @@ export async function updateSolarEclipse2024Data(userUUID: string, update: Solar
if (update.delta_app_time_ms) {
dbUpdate.app_time_ms = data.app_time_ms + update.delta_app_time_ms;
}
if (update.delta_advanced_weather_time_ms) {
dbUpdate.advanced_weather_time_ms = data.advanced_weather_time_ms + update.delta_advanced_weather_time_ms;
}
const result = await data.update(dbUpdate);
return result !== null;
}
6 changes: 6 additions & 0 deletions src/stories/solar-eclipse-2024/models/eclipse_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class SolarEclipse2024Data extends Model<InferAttributes<SolarEclipse2024
declare cloud_cover_selected_locations_count: number;
declare info_time_ms: CreationOptional<number>;
declare app_time_ms: CreationOptional<number>;
declare advanced_weather_time_ms: CreationOptional<number>;
declare timestamp: CreationOptional<Date>;
}

Expand Down Expand Up @@ -51,6 +52,11 @@ export function initializeSolarEclipse2024DataModel(sequelize: Sequelize) {
allowNull: false,
defaultValue: 0
},
advanced_weather_time_ms: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
timestamp: {
type: DataTypes.DATE,
allowNull: false,
Expand Down
4 changes: 4 additions & 0 deletions src/stories/solar-eclipse-2024/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ router.put("/data", async (req, res) => {
router.get("/data/:uuid", async (req, res) => {
const uuid = req.params.uuid as string;
const response = await getSolarEclipse2024Data(uuid);
if (response === null) {
res.status(404).json({ error: "Specified user data does not exist" });
return;
}
res.json({ response });
});

Expand Down
15 changes: 15 additions & 0 deletions src/stories/solar-eclipse-2024/sql/create_eclipse_data_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE SolarEclipse2024Data (
id int(11) UNSIGNED NOT NULL UNIQUE AUTO_INCREMENT,
user_uuid varchar(36) NOT NULL UNIQUE,
user_selected_locations JSON NOT NULL,
user_selected_locations_count INT NOT NULL,
cloud_cover_selected_locations JSON NOT NULL,
cloud_cover_selected_locations_count INT NOT NULL,
app_time_ms INT NOT NULL DEFAULT 0,
info_time_ms INT NOT NULL DEFAULT 0,
advanced_weather_time_ms INT NOT NULL DEFAULT 0,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

PRIMARY KEY(id),
INDEX(user_uuid)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci PACK_KEYS=0;

0 comments on commit 82e7b36

Please sign in to comment.