Skip to content

Commit

Permalink
Merge pull request #108 from Carifio24/add-more-stuff
Browse files Browse the repository at this point in the history
Add more fields to solar eclipse data
  • Loading branch information
Carifio24 authored Mar 22, 2024
2 parents 7bf0b4f + d76662c commit 5262704
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/stories/solar-eclipse-2024/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@ export const SolarEclipse2024Entry = S.struct({
user_uuid: S.string,
user_selected_locations: LatLonArray,
cloud_cover_selected_locations: LatLonArray,
text_search_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 }),
weather_info_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
user_guide_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
eclipse_timer_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 }),
text_search_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 }),
delta_weather_info_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
delta_user_guide_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
delta_eclipse_timer_time_ms: S.optional(S.number.pipe(S.int()), { exact: true }),
});

export type SolarEclipse2024DataT = S.Schema.To<typeof SolarEclipse2024Entry>;
Expand All @@ -40,6 +46,7 @@ export async function submitSolarEclipse2024Data(data: SolarEclipse2024DataT): P
...data,
user_selected_locations_count: data.user_selected_locations.length,
cloud_cover_selected_locations_count: data.cloud_cover_selected_locations.length,
text_search_locations_count: data.text_search_locations.length,
};

return SolarEclipse2024Data.upsert(dataWithCounts).then(([item, _]) => item);
Expand Down Expand Up @@ -71,6 +78,11 @@ export async function updateSolarEclipse2024Data(userUUID: string, update: Solar
dbUpdate.cloud_cover_selected_locations = selected;
dbUpdate.cloud_cover_selected_locations_count = selected.length;
}
if (update.text_search_locations) {
const selected = data.text_search_locations.concat(update.text_search_locations);
dbUpdate.text_search_locations = selected;
dbUpdate.text_search_locations_count = selected.length;
}
if (update.delta_info_time_ms) {
dbUpdate.info_time_ms = data.info_time_ms + update.delta_info_time_ms;
}
Expand All @@ -83,6 +95,12 @@ export async function updateSolarEclipse2024Data(userUUID: string, update: Solar
if (update.delta_weather_info_time_ms) {
dbUpdate.weather_info_time_ms = data.weather_info_time_ms + update.delta_weather_info_time_ms;
}
if (update.delta_user_guide_time_ms) {
dbUpdate.user_guide_time_ms = data.user_guide_time_ms + update.delta_user_guide_time_ms;
}
if (update.delta_eclipse_timer_time_ms) {
dbUpdate.eclipse_timer_time_ms = data.eclipse_timer_time_ms + update.delta_eclipse_timer_time_ms;
}
const result = await data.update(dbUpdate);
return result !== null;
}
22 changes: 22 additions & 0 deletions src/stories/solar-eclipse-2024/models/eclipse_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ export class SolarEclipse2024Data extends Model<InferAttributes<SolarEclipse2024
declare user_selected_locations_count: number;
declare cloud_cover_selected_locations: [number, number][];
declare cloud_cover_selected_locations_count: number;
declare text_search_locations: [number, number][];
declare text_search_locations_count: number;
declare info_time_ms: CreationOptional<number>;
declare app_time_ms: CreationOptional<number>;
declare advanced_weather_time_ms: CreationOptional<number>;
declare weather_info_time_ms: CreationOptional<number>;
declare user_guide_time_ms: CreationOptional<number>;
declare eclipse_timer_time_ms: CreationOptional<number>;
declare timestamp: CreationOptional<Date>;
}

Expand Down Expand Up @@ -43,6 +47,14 @@ export function initializeSolarEclipse2024DataModel(sequelize: Sequelize) {
type: DataTypes.INTEGER,
allowNull: false
},
text_search_locations: {
type: DataTypes.JSON,
allowNull: false
},
text_search_locations_count: {
type: DataTypes.INTEGER,
allowNull: false
},
info_time_ms: {
type: DataTypes.INTEGER,
allowNull: false,
Expand All @@ -63,6 +75,16 @@ export function initializeSolarEclipse2024DataModel(sequelize: Sequelize) {
allowNull: false,
defaultValue: 0
},
user_guide_time_ms: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
eclipse_timer_time_ms: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
timestamp: {
type: DataTypes.DATE,
allowNull: false,
Expand Down
1 change: 0 additions & 1 deletion src/stories/solar-eclipse-2024/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as S from "@effect/schema/Schema";
import * as Either from "effect/Either";
import { Router } from "express";
import {
getAllSolarEclipse2024Data,
getSolarEclipse2024Data,
submitSolarEclipse2024Data,
SolarEclipse2024Entry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ CREATE TABLE SolarEclipse2024Data (
user_selected_locations_count INT NOT NULL,
cloud_cover_selected_locations JSON NOT NULL,
cloud_cover_selected_locations_count INT NOT NULL,
text_search_locations JSON NOT NULL,
text_search_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,
weather_info_time_ms INT NOT NULL DEFAULT 0,
user_guide_time_ms INT NOT NULL DEFAULT 0,
eclipse_timer_time_ms INT NOT NULL DEFAULT 0,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

PRIMARY KEY(id),
Expand Down

0 comments on commit 5262704

Please sign in to comment.