Skip to content

Commit

Permalink
added efficient numeric score calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lizdotsh committed Oct 20, 2023
1 parent fc36d2e commit 0768be0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 116 deletions.
3 changes: 2 additions & 1 deletion electron/api.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module.exports = {
// getPersonStatNameAgnostic: photo_info.getPersonStatNameAgnostic,
// getDailyZeroedCounts: person.getDailyZeroedCounts,
// getDailyZeroedCountsNameAgnostic: photo_info.getDailyZeroedCountsNameAgnostic,
getCurationScore: person.getCurationScore
getCurationScore: person.getCurationScore,
getNumericScoresTime: person.getNumericScoresTime,
}
170 changes: 66 additions & 104 deletions electron/assets/rollup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -290,42 +290,42 @@ ON people_sum_daily(person_uuid, DATE);
DROP TABLE IF EXISTS numeric_scores_monthly;

CREATE TABLE numeric_scores_monthly AS
with unweighted as (
-- with unweighted as (
SELECT
person_uuid,
strftime('%Y-%m', date_created) || '-01' AS YEAR_MONTH,
COUNT(DISTINCT zuuid) AS COUNT,
AVG(curation_score) AS curation_score,
AVG(zm_activity_score) AS activity_score,
AVG(zm_video_score) AS video_score,
AVG(zm_audio_score) AS audio_score,
AVG(zm_wallpaper_score) AS wallpaper_score,
AVG(zm_autoplay_suggestion_score) AS autoplay_suggestion_score,
AVG(zm_blurriness_score) AS blurriness_score,
AVG(zm_exposure_score) AS exposure_score,
AVG(zc_behavioral_score) AS behavioral_score,
AVG(zc_failure_score) AS failure_score,
AVG(zc_harmonious_color_score) AS harmonious_color_score,
AVG(zc_immersiveness_score) AS immersiveness_score,
AVG(zc_interaction_score) AS interaction_score,
AVG(zc_interesting_subject_score) AS interesting_subject_score,
AVG(zc_intrusive_object_presence_score) AS intrusive_object_presence_score,
AVG(zc_lively_color_score) AS lively_color_score,
AVG(zc_low_light) AS low_light,
AVG(zc_noise_score) AS noise_score,
AVG(zc_pleasant_camera_tilt_score) AS pleasant_camera_tilt_score,
AVG(zc_pleasant_composition_score) AS pleasant_composition_score,
AVG(zc_pleasant_lighting_score) AS pleasant_lighting_score,
AVG(zc_pleasant_pattern_score) AS pleasant_pattern_score,
AVG(zc_pleasant_perspective_score) AS pleasant_perspective_score,
AVG(zc_pleasant_post_processing_score) AS pleasant_post_processing_score,
AVG(zc_pleasant_reflection_score) AS pleasant_reflection_score,
AVG(zc_pleasant_symmetry_score) AS pleasant_symmetry_score,
AVG(zc_sharply_focused_subject_score) AS sharply_focused_subject_score,
AVG(zc_tastefully_blurred_score) AS tastefully_blurred_score,
AVG(zc_well_chosen_subject_score) AS well_chosen_subject_score,
AVG(zc_well_framed_subject_score) AS well_framed_subject_score,
AVG(zc_well_timed_shot_score) AS well_timed_shot_score
COUNT( zuuid) AS COUNT,
SUM(curation_score) AS curation_score,
SUM(zm_activity_score) AS activity_score,
SUM(zm_video_score) AS video_score,
SUM(zm_audio_score) AS audio_score,
SUM(zm_wallpaper_score) AS wallpaper_score,
SUM(zm_autoplay_suggestion_score) AS autoplay_suggestion_score,
SUM(zm_blurriness_score) AS blurriness_score,
SUM(zm_exposure_score) AS exposure_score,
SUM(zc_behavioral_score) AS behavioral_score,
SUM(zc_failure_score) AS failure_score,
SUM(zc_harmonious_color_score) AS harmonious_color_score,
SUM(zc_immersiveness_score) AS immersiveness_score,
SUM(zc_interaction_score) AS interaction_score,
SUM(zc_interesting_subject_score) AS interesting_subject_score,
SUM(zc_intrusive_object_presence_score) AS intrusive_object_presence_score,
SUM(zc_lively_color_score) AS lively_color_score,
SUM(zc_low_light) AS low_light,
SUM(zc_noise_score) AS noise_score,
SUM(zc_pleasant_camera_tilt_score) AS pleasant_camera_tilt_score,
SUM(zc_pleasant_composition_score) AS pleasant_composition_score,
SUM(zc_pleasant_lighting_score) AS pleasant_lighting_score,
SUM(zc_pleasant_pattern_score) AS pleasant_pattern_score,
SUM(zc_pleasant_perspective_score) AS pleasant_perspective_score,
SUM(zc_pleasant_post_processing_score) AS pleasant_post_processing_score,
SUM(zc_pleasant_reflection_score) AS pleasant_reflection_score,
SUM(zc_pleasant_symmetry_score) AS pleasant_symmetry_score,
SUM(zc_sharply_focused_subject_score) AS sharply_focused_subject_score,
SUM(zc_tastefully_blurred_score) AS tastefully_blurred_score,
SUM(zc_well_chosen_subject_score) AS well_chosen_subject_score,
SUM(zc_well_framed_subject_score) AS well_framed_subject_score,
SUM(zc_well_timed_shot_score) AS well_timed_shot_score
FROM photo_info
WHERE
person_uuid IS NOT NULL
Expand All @@ -336,79 +336,41 @@ UNION ALL
SELECT
'---' AS person_uuid,
strftime('%Y-%m', date_created) || '-01' AS YEAR_MONTH,
COUNT(DISTINCT zuuid) AS COUNT,
AVG(curation_score) AS curation_score,
AVG(zm_activity_score) AS activity_score,
AVG(zm_video_score) AS video_score,
AVG(zm_audio_score) AS audio_score,
AVG(zm_wallpaper_score) AS wallpaper_score,
AVG(zm_autoplay_suggestion_score) AS autoplay_suggestion_score,
AVG(zm_blurriness_score) AS blurriness_score,
AVG(zm_exposure_score) AS exposure_score,
AVG(zc_behavioral_score) AS behavioral_score,
AVG(zc_failure_score) AS failure_score,
AVG(zc_harmonious_color_score) AS harmonious_color_score,
AVG(zc_immersiveness_score) AS immersiveness_score,
AVG(zc_interaction_score) AS interaction_score,
AVG(zc_interesting_subject_score) AS interesting_subject_score,
AVG(zc_intrusive_object_presence_score) AS intrusive_object_presence_score,
AVG(zc_lively_color_score) AS lively_color_score,
AVG(zc_low_light) AS low_light,
AVG(zc_noise_score) AS noise_score,
AVG(zc_pleasant_camera_tilt_score) AS pleasant_camera_tilt_score,
AVG(zc_pleasant_composition_score) AS pleasant_composition_score,
AVG(zc_pleasant_lighting_score) AS pleasant_lighting_score,
AVG(zc_pleasant_pattern_score) AS pleasant_pattern_score,
AVG(zc_pleasant_perspective_score) AS pleasant_perspective_score,
AVG(zc_pleasant_post_processing_score) AS pleasant_post_processing_score,
AVG(zc_pleasant_reflection_score) AS pleasant_reflection_score,
AVG(zc_pleasant_symmetry_score) AS pleasant_symmetry_score,
AVG(zc_sharply_focused_subject_score) AS sharply_focused_subject_score,
AVG(zc_tastefully_blurred_score) AS tastefully_blurred_score,
AVG(zc_well_chosen_subject_score) AS well_chosen_subject_score,
AVG(zc_well_framed_subject_score) AS well_framed_subject_score,
AVG(zc_well_timed_shot_score) AS well_timed_shot_score
COUNT( zuuid) AS COUNT,
SUM(curation_score) AS curation_score,
SUM(zm_activity_score) AS activity_score,
SUM(zm_video_score) AS video_score,
SUM(zm_audio_score) AS audio_score,
SUM(zm_wallpaper_score) AS wallpaper_score,
SUM(zm_autoplay_suggestion_score) AS autoplay_suggestion_score,
SUM(zm_blurriness_score) AS blurriness_score,
SUM(zm_exposure_score) AS exposure_score,
SUM(zc_behavioral_score) AS behavioral_score,
SUM(zc_failure_score) AS failure_score,
SUM(zc_harmonious_color_score) AS harmonious_color_score,
SUM(zc_immersiveness_score) AS immersiveness_score,
SUM(zc_interaction_score) AS interaction_score,
SUM(zc_interesting_subject_score) AS interesting_subject_score,
SUM(zc_intrusive_object_presence_score) AS intrusive_object_presence_score,
SUM(zc_lively_color_score) AS lively_color_score,
SUM(zc_low_light) AS low_light,
SUM(zc_noise_score) AS noise_score,
SUM(zc_pleasant_camera_tilt_score) AS pleasant_camera_tilt_score,
SUM(zc_pleasant_composition_score) AS pleasant_composition_score,
SUM(zc_pleasant_lighting_score) AS pleasant_lighting_score,
SUM(zc_pleasant_pattern_score) AS pleasant_pattern_score,
SUM(zc_pleasant_perspective_score) AS pleasant_perspective_score,
SUM(zc_pleasant_post_processing_score) AS pleasant_post_processing_score,
SUM(zc_pleasant_reflection_score) AS pleasant_reflection_score,
SUM(zc_pleasant_symmetry_score) AS pleasant_symmetry_score,
SUM(zc_sharply_focused_subject_score) AS sharply_focused_subject_score,
SUM(zc_tastefully_blurred_score) AS tastefully_blurred_score,
SUM(zc_well_chosen_subject_score) AS well_chosen_subject_score,
SUM(zc_well_framed_subject_score) AS well_framed_subject_score,
SUM(zc_well_timed_shot_score) AS well_timed_shot_score
FROM photo_info
GROUP BY 1, 2
order by year_month)

select
person_uuid,
year_month,
count,
curation_score * count as curation_score,
activity_score * count as activity_score,
video_score * count as video_score,
audio_score * count as audio_score,
wallpaper_score * count as wallpaper_score,
autoplay_suggestion_score * count as autoplay_suggestion_score,
blurriness_score * count as blurriness_score,
exposure_score * count as exposure_score,
behavioral_score * count as behavioral_score,
failure_score * count as failure_score,
harmonious_color_score * count as harmonious_color_score,
immersiveness_score * count as immersiveness_score,
interaction_score * count as interaction_score,
interesting_subject_score * count as interesting_subject_score,
intrusive_object_presence_score * count as intrusive_object_presence_score,
lively_color_score * count as lively_color_score,
low_light * count as low_light,
noise_score * count as noise_score,
pleasant_camera_tilt_score * count as pleasant_camera_tilt_score,
pleasant_composition_score * count as pleasant_composition_score,
pleasant_lighting_score * count as pleasant_lighting_score,
pleasant_pattern_score * count as pleasant_pattern_score,
pleasant_perspective_score * count as pleasant_perspective_score,
pleasant_post_processing_score * count as pleasant_post_processing_score,
pleasant_reflection_score * count as pleasant_reflection_score,
pleasant_symmetry_score * count as pleasant_symmetry_score,
sharply_focused_subject_score * count as sharply_focused_subject_score,
tastefully_blurred_score * count as tastefully_blurred_score,
well_chosen_subject_score * count as well_chosen_subject_score,
well_framed_subject_score * count as well_framed_subject_score,
well_timed_shot_score * count as well_timed_shot_score
from unweighted;

order by year_month;

CREATE INDEX numeric_scores_monthly_uuid_date_index
ON numeric_scores_monthly(person_uuid, YEAR_MONTH);
23 changes: 18 additions & 5 deletions electron/models/person.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,25 @@ exports.getCurationScore = function(person_id, start_date, end_date) {
// `
// }
exports.getNumericScoresTime = function(person_id, start_date, end_date) {
query = `select
person_uuid,
year_month,
${numeric_scores_as_arr_of_objects.map(score => `avg(${score.alais}) * count as ${score.alias}`).join(",\n")}

query = `
with total as (select sum(count) as tot
from numeric_scores_monthly
where person_uuid = :person_id
and year_month >= :start_date
and year_month <= :end_date
)
select
${numeric_scores_as_arr_of_objects.map(score => `sum(${score.alias}) / total.tot as ${score.alias}`).join(",\n")}
from numeric_scores_monthly n
left join total on 1 = 1
where person_uuid = :person_id
and year_month >= :start_date
and year_month <= :end_date
group by person_uuid
`;
return txGetOne(query, {person_id, start_date, end_date});
}

// const numeric_scores = {
// "curation_score": "curation_score",
// "zm_activity_score": "activity_score",
Expand Down
12 changes: 6 additions & 6 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@
});
$: console.log(start_date, end_date);
$: console.log([start_date, end_date]);
// let person_numeric_scores;
// $: api.getCurationScore(person?.person_uuid, start_date, end_date).then(d => {
// person_numeric_scores = d;
// console.log(d);
// });
let person_numeric_scores;
$: api.getNumericScoresTime(person?.person_uuid, start_date, end_date).then(d => {
person_numeric_scores = d;
console.log(d);
});
// $: console.log(people[person_id]);
</script>
Expand All @@ -135,7 +135,7 @@
{#if activeTab === "Tab1"}
<!-- {/if} -->
<!-- <NumericScores {person_numeric_scores} /> -->
<NumericScores {person_numeric_scores} />
<div id="not-sticky">
<div class="flex-container">
<div id="time">
Expand Down

0 comments on commit 0768be0

Please sign in to comment.