Skip to content

Commit

Permalink
Update SQL and model definitions for solar eclipse data. Update field…
Browse files Browse the repository at this point in the history
… names in database functions.
  • Loading branch information
Carifio24 committed Mar 8, 2024
1 parent 417567f commit 1256d7d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/stories/solar-eclipse-2024/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const LatLonArray = S.mutable(S.array(S.mutable(S.tuple(S.number, S.number))));

export const SolarEclipse2024Entry = S.struct({
user_uuid: S.string,
selected_locations: LatLonArray,
user_selected_locations: LatLonArray,
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 }),
});

export const SolarEclipse2024Update = S.struct({
selected_locations: S.optional(LatLonArray, { exact: true }),
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 }),
Expand All @@ -34,7 +34,7 @@ export async function submitSolarEclipse2024Response(data: SolarEclipse2024DataT

const dataWithCounts = {
...data,
selected_locations_count: data.selected_locations.length,
user_selected_locations_count: data.user_selected_locations.length,
cloud_cover_selected_locations_count: data.cloud_cover_selected_locations.length,
};

Expand All @@ -57,10 +57,10 @@ export async function updateSolarEclipse2024Data(userUUID: string, update: Solar
return false;
}
const dbUpdate: SolarEclipse2024UpdateAttributes = {};
if (update.selected_locations) {
const selected = data.selected_locations.concat(update.selected_locations);
dbUpdate.selected_locations = selected;
dbUpdate.selected_locations_count = selected.length;
if (update.user_selected_locations) {
const selected = data.user_selected_locations.concat(update.user_selected_locations);
dbUpdate.user_selected_locations = selected;
dbUpdate.user_selected_locations_count = selected.length;
}
if (update.cloud_cover_selected_locations) {
const selected = data.cloud_cover_selected_locations.concat(update.cloud_cover_selected_locations);
Expand Down
10 changes: 6 additions & 4 deletions src/stories/solar-eclipse-2024/models/eclipse_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Sequelize, DataTypes, Model, InferAttributes, InferCreationAttributes,
export class SolarEclipse2024Data extends Model<InferAttributes<SolarEclipse2024Data>, InferCreationAttributes<SolarEclipse2024Data>> {
declare id: CreationOptional<number>;
declare user_uuid: string;
declare selected_locations: [number, number][];
declare selected_locations_count: number;
declare user_selected_locations: [number, number][];
declare user_selected_locations_count: number;
declare cloud_cover_selected_locations: [number, number][];
declare cloud_cover_selected_locations_count: number;
declare info_time_ms: CreationOptional<number>;
Expand All @@ -25,11 +25,11 @@ export function initializeSolarEclipse2024DataModel(sequelize: Sequelize) {
unique: true,
allowNull: false
},
selected_locations: {
user_selected_locations: {
type: DataTypes.JSON,
allowNull: false
},
selected_locations_count: {
user_selected_locations_count: {
type: DataTypes.INTEGER,
allowNull: false
},
Expand All @@ -43,10 +43,12 @@ export function initializeSolarEclipse2024DataModel(sequelize: Sequelize) {
},
info_time_ms: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
app_time_ms: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
timestamp: {
Expand Down

This file was deleted.

0 comments on commit 1256d7d

Please sign in to comment.