From 1256d7da655c71eb1587a521383481912053a058 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Fri, 8 Mar 2024 14:17:43 -0500 Subject: [PATCH] Update SQL and model definitions for solar eclipse data. Update field names in database functions. --- src/stories/solar-eclipse-2024/database.ts | 14 +++++++------- .../solar-eclipse-2024/models/eclipse_data.ts | 10 ++++++---- .../sql/create_eclipse_response_table.sql | 10 ---------- 3 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 src/stories/solar-eclipse-2024/sql/create_eclipse_response_table.sql diff --git a/src/stories/solar-eclipse-2024/database.ts b/src/stories/solar-eclipse-2024/database.ts index f4b72c3..74041ae 100644 --- a/src/stories/solar-eclipse-2024/database.ts +++ b/src/stories/solar-eclipse-2024/database.ts @@ -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 }), @@ -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, }; @@ -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); diff --git a/src/stories/solar-eclipse-2024/models/eclipse_data.ts b/src/stories/solar-eclipse-2024/models/eclipse_data.ts index 3219e4d..fd97067 100644 --- a/src/stories/solar-eclipse-2024/models/eclipse_data.ts +++ b/src/stories/solar-eclipse-2024/models/eclipse_data.ts @@ -3,8 +3,8 @@ import { Sequelize, DataTypes, Model, InferAttributes, InferCreationAttributes, export class SolarEclipse2024Data extends Model, InferCreationAttributes> { declare id: CreationOptional; 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; @@ -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 }, @@ -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: { diff --git a/src/stories/solar-eclipse-2024/sql/create_eclipse_response_table.sql b/src/stories/solar-eclipse-2024/sql/create_eclipse_response_table.sql deleted file mode 100644 index 3ee8ffa..0000000 --- a/src/stories/solar-eclipse-2024/sql/create_eclipse_response_table.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE SolarEclipse2024Responses ( - 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, - 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;