Add session mood results and statistics

This commit is contained in:
waozi committed 2026-08-25 15:01:20 -03:00
1 parent 4e88505ce4
commit eaf9abd4de
28 files changed
+1300 -23

No files matched your search

+33
View File
@@ -854,6 +854,15 @@ Vzorec podle dnů v týdnu
[habit_stats_practice_time]
Čas cvičení
---
[habit_stats_mood_title]
Nálada po cvičení
---
[habit_stats_mood_average]
Průměrná nálada
---
[habit_stats_mood_checkins]
Záznamy
---
[habit_stats_best_hold]
Nejlepší zádrž
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Hotovo
---
[results_duration]
Délka %s
---
[results_pattern]
Vzor %s
---
[results_cycles]
%d cyklů
---
[results_repetitions]
%d opakování
---
[results_saved_status]
Uloženo do historie
---
[results_unsaved_status]
Neuloženo (méně než jedna minuta)
---
[results_mood_title]
Jak jste se cítili?
---
+33
View File
@@ -854,6 +854,15 @@ Wochentagsmuster
[habit_stats_practice_time]
Übungszeit
---
[habit_stats_mood_title]
Stimmung nach der Übung
---
[habit_stats_mood_average]
Durchschnittliche Stimmung
---
[habit_stats_mood_checkins]
Check-ins
---
[habit_stats_best_hold]
Beste Atemhaltezeit
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Fertig
---
[results_duration]
Dauer %s
---
[results_pattern]
Muster %s
---
[results_cycles]
%d Zyklen
---
[results_repetitions]
%d Wiederholungen
---
[results_saved_status]
In der Historie gespeichert
---
[results_unsaved_status]
Nicht gespeichert (unter einer Minute)
---
[results_mood_title]
Wie hast du dich gefühlt?
---
+33
View File
@@ -351,6 +351,9 @@ Save
[discard_button]
Discard
---
[done_button]
Done
---
[all_progress_lost_message]
All progress will be lost.
---
@@ -1095,6 +1098,15 @@ Weekday pattern
[habit_stats_practice_time]
Practice time
---
[habit_stats_mood_title]
Mood after practice
---
[habit_stats_mood_average]
Average mood
---
[habit_stats_mood_checkins]
Check-ins
---
[habit_stats_best_hold]
Best hold
---
@@ -1184,6 +1196,27 @@ Session data comes from completed practices.
[results_rounds]
%d rounds
---
[results_duration]
Duration %s
---
[results_pattern]
Pattern %s
---
[results_cycles]
%d cycles
---
[results_repetitions]
%d repetitions
---
[results_saved_status]
Saved to history
---
[results_unsaved_status]
Not saved (under one minute)
---
[results_mood_title]
How did you feel?
---
[practice_home_minutes]
%d min
---
+33
View File
@@ -854,6 +854,15 @@ Patrón semanal
[habit_stats_practice_time]
Tiempo de práctica
---
[habit_stats_mood_title]
Ánimo después de practicar
---
[habit_stats_mood_average]
Ánimo promedio
---
[habit_stats_mood_checkins]
Registros
---
[habit_stats_best_hold]
Mejor retención
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Listo
---
[results_duration]
Duración %s
---
[results_pattern]
Patrón %s
---
[results_cycles]
%d ciclos
---
[results_repetitions]
%d repeticiones
---
[results_saved_status]
Guardado en el historial
---
[results_unsaved_status]
No guardado (menos de un minuto)
---
[results_mood_title]
¿Cómo te sentiste?
---
+33
View File
@@ -890,6 +890,15 @@ Rythme par jour
[habit_stats_practice_time]
Temps de pratique
---
[habit_stats_mood_title]
Humeur après la pratique
---
[habit_stats_mood_average]
Humeur moyenne
---
[habit_stats_mood_checkins]
Bilans
---
[habit_stats_best_hold]
Meilleure rétention
---
@@ -1751,3 +1760,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Terminé
---
[results_duration]
Durée %s
---
[results_pattern]
Rythme %s
---
[results_cycles]
%d cycles
---
[results_repetitions]
%d répétitions
---
[results_saved_status]
Enregistré dans l'historique
---
[results_unsaved_status]
Non enregistré (moins d'une minute)
---
[results_mood_title]
Comment vous sentiez-vous ?
---
+33
View File
@@ -854,6 +854,15 @@ Pola hari
[habit_stats_practice_time]
Waktu latihan
---
[habit_stats_mood_title]
Suasana hati setelah latihan
---
[habit_stats_mood_average]
Suasana hati rata-rata
---
[habit_stats_mood_checkins]
Check-in
---
[habit_stats_best_hold]
Tahan terbaik
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Selesai
---
[results_duration]
Durasi %s
---
[results_pattern]
Pola %s
---
[results_cycles]
%d siklus
---
[results_repetitions]
%d pengulangan
---
[results_saved_status]
Disimpan ke riwayat
---
[results_unsaved_status]
Tidak disimpan (kurang dari satu menit)
---
[results_mood_title]
Bagaimana perasaan Anda?
---
+33
View File
@@ -854,6 +854,15 @@ Schema settimanale
[habit_stats_practice_time]
Tempo di pratica
---
[habit_stats_mood_title]
Umore dopo la pratica
---
[habit_stats_mood_average]
Umore medio
---
[habit_stats_mood_checkins]
Check-in
---
[habit_stats_best_hold]
Migliore apnea
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Fine
---
[results_duration]
Durata %s
---
[results_pattern]
Schema %s
---
[results_cycles]
%d cicli
---
[results_repetitions]
%d ripetizioni
---
[results_saved_status]
Salvato nella cronologia
---
[results_unsaved_status]
Non salvato (meno di un minuto)
---
[results_mood_title]
Come ti sei sentito?
---
+33
View File
@@ -856,6 +856,15 @@ Description
[habit_stats_practice_time]
練習時間
---
[habit_stats_mood_title]
練習後の気分
---
[habit_stats_mood_average]
平均気分
---
[habit_stats_mood_checkins]
チェックイン
---
[habit_stats_best_hold]
最長息止め
---
@@ -1754,3 +1763,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
完了
---
[results_duration]
時間 %s
---
[results_pattern]
パターン %s
---
[results_cycles]
%d サイクル
---
[results_repetitions]
%d 回
---
[results_saved_status]
履歴に保存しました
---
[results_unsaved_status]
保存されませんでした(1分未満)
---
[results_mood_title]
気分はどうでしたか?
---
+33
View File
@@ -853,6 +853,15 @@ Description
[habit_stats_practice_time]
연습 시간
---
[habit_stats_mood_title]
연습 후 기분
---
[habit_stats_mood_average]
평균 기분
---
[habit_stats_mood_checkins]
체크인
---
[habit_stats_best_hold]
최고 숨 참기
---
@@ -1751,3 +1760,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
완료
---
[results_duration]
시간 %s
---
[results_pattern]
패턴 %s
---
[results_cycles]
%d회 사이클
---
[results_repetitions]
%d회 반복
---
[results_saved_status]
기록에 저장됨
---
[results_unsaved_status]
저장되지 않음(1분 미만)
---
[results_mood_title]
기분이 어땠나요?
---
+33
View File
@@ -854,6 +854,15 @@ Padrão por dia da semana
[habit_stats_practice_time]
Tempo de prática
---
[habit_stats_mood_title]
Humor após a prática
---
[habit_stats_mood_average]
Humor médio
---
[habit_stats_mood_checkins]
Check-ins
---
[habit_stats_best_hold]
Melhor retenção
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Concluído
---
[results_duration]
Duração %s
---
[results_pattern]
Padrão %s
---
[results_cycles]
%d ciclos
---
[results_repetitions]
%d repetições
---
[results_saved_status]
Salvo no histórico
---
[results_unsaved_status]
Não salvo (menos de um minuto)
---
[results_mood_title]
Como você se sentiu?
---
+33
View File
@@ -854,6 +854,15 @@ Description
[habit_stats_practice_time]
Время практики
---
[habit_stats_mood_title]
Настроение после практики
---
[habit_stats_mood_average]
Среднее настроение
---
[habit_stats_mood_checkins]
Отметки
---
[habit_stats_best_hold]
Лучшая задержка
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
Готово
---
[results_duration]
Длительность %s
---
[results_pattern]
Паттерн %s
---
[results_cycles]
%d циклов
---
[results_repetitions]
%d повторений
---
[results_saved_status]
Сохранено в истории
---
[results_unsaved_status]
Не сохранено (меньше одной минуты)
---
[results_mood_title]
Как вы себя чувствовали?
---
+33
View File
@@ -854,6 +854,15 @@ Wim Hof 屏息轮次
[habit_stats_practice_time]
练习时间
---
[habit_stats_mood_title]
练习后的心情
---
[habit_stats_mood_average]
平均心情
---
[habit_stats_mood_checkins]
打卡
---
[habit_stats_best_hold]
最佳屏息
---
@@ -1752,3 +1761,27 @@ Skip this time
[donation_reminder_dismiss_button]
Dismiss forever
---
[done_button]
完成
---
[results_duration]
时长 %s
---
[results_pattern]
模式 %s
---
[results_cycles]
%d 个循环
---
[results_repetitions]
%d 次重复
---
[results_saved_status]
已保存到历史记录
---
[results_unsaved_status]
未保存(少于一分钟)
---
[results_mood_title]
你感觉怎么样?
---
+21
View File
@@ -34,6 +34,7 @@
#include "practices/meditation/meditation_practice.h"
#include "practices/whm/whm_session.h"
#include "sync_account.h"
#include "../../vendor/kryon/src/ui/ui_internal.h"
#include <limits.h>
#include <stdio.h>
@@ -77,6 +78,25 @@ typedef struct AppProfileStats {
static AppProfileStats g_app_profile;
int
TextButton(int id, int x, int y, const char *label, int *hover)
{
(void)id;
return RenderTextButton(x, y, label, hover);
}
int
LocaleDropdown(int id, int x, int y, int w, int h, int *selected_index)
{
return DrawUILocaleDropdown(id, x, y, w, h, selected_index);
}
void
ReadonlyTextBox(ReadonlyTextBoxProps props)
{
DrawUIReadonlyTextBox(props);
}
static void app_apply_route(InbeApp *app, AppRoute route);
typedef struct InbeRouteBinding {
@@ -1425,6 +1445,7 @@ app_init(void *vapp) {
inbe_update_check_start();
app->practice_tab = PRACTICE_TAB_PLAY;
app->practice_config_tab = 0;
memset(&app->session_result, 0, sizeof(app->session_result));
if(app->language_needs_save) {
save_settings(app);
app->language_needs_save = 0;
+22
View File
@@ -12,6 +12,10 @@
#include "screens/settings/settings_types.h"
#include "storage/sync_account.h"
int TextButton(int id, int x, int y, const char *label, int *hover);
int LocaleDropdown(int id, int x, int y, int w, int h, int *selected_index);
void ReadonlyTextBox(ReadonlyTextBoxProps props);
enum {
SETTINGS_SPEED_MIN = 1,
SETTINGS_SPEED_MAX = 8,
@@ -368,6 +372,19 @@ typedef struct HabitEditState {
int reminder_hour;
} HabitEditState;
typedef struct InbeSessionResult {
int active;
int activity;
int primary_value;
int secondary_value;
int saved;
int mood;
int round_count;
int round_values[MaxRounds];
char detail[96];
char path[FS_PATH_MAX];
} InbeSessionResult;
struct InbeApp {
Inbe inbe;
Inbe settings_preview;
@@ -534,6 +551,7 @@ struct InbeApp {
int backgrounded;
double desktop_background_last_time;
int results_saved;
InbeSessionResult session_result;
int input_block_frame;
int close_prompt_open;
int close_prompt_input_block_frame;
@@ -667,6 +685,10 @@ int exercise_manual_seen(InbeApp *app, int exercise_type);
void mark_exercise_manual_seen(InbeApp *app, int exercise_type);
void sync_habits_for_activity(InbeApp *app, int exercise_type);
void draw_preview_inbe(Inbe *inbe, int center_x, int center_y);
void app_prepare_session_results(InbeApp *app, int activity, int primary_value,
int secondary_value, const char *detail,
const int *round_values, int round_count,
const char *saved_path);
#include "app_nav.h"
#include "app/app_settings.h"
+50 -3
View File
@@ -651,14 +651,20 @@ screenshot_seed_habits(InbeApp *app)
for(int day = 6; day >= 0; day--) {
int progress = 6 - day;
int local_date = screenshot_day_index_offset(day);
char session_path[FS_PATH_MAX] = {0};
InbeStorageSessionCheckin checkin = {0};
int rounds[] = {
32 + progress * 4,
37 + progress * 4,
41 + progress * 5
};
storage_save_session_at_for_activity(local_date, 7, 15 + progress, 0,
rounds, 3, 0, EXERCISE_WIM_HOF,
NULL, 0);
if(storage_save_session_at_for_activity(local_date, 7, 15 + progress, 0,
rounds, 3, 0, EXERCISE_WIM_HOF,
session_path,
sizeof(session_path))) {
checkin.mood_after = 3 + (progress % 3);
storage_save_session_checkin(session_path, &checkin);
}
}
}
@@ -680,6 +686,39 @@ screenshot_apply_theme(InbeApp *app, int theme_id, int dark_mode)
app_refresh_theme(app);
}
static void
screenshot_setup_result_scene(InbeApp *app, int activity)
{
if(app == NULL)
return;
app->main_tab = APP_MAIN_TAB_PRACTICE;
app->exercise_type = activity;
app->inbe.screen = InbeScreenResults;
if(activity == EXERCISE_WIM_HOF) {
int rounds[] = {48, 61, 74, 69};
app_prepare_session_results(app, EXERCISE_WIM_HOF, 0, 0, NULL,
rounds, 4, "db:screenshot-whm");
app->session_result.mood = 4;
} else if(activity == EXERCISE_MEDITATION) {
app_prepare_session_results(app, EXERCISE_MEDITATION, 15 * 60, 0,
NULL, NULL, 0,
"db:screenshot-meditation");
app->session_result.mood = 5;
} else if(activity == EXERCISE_SUN_SALUTATION) {
app_prepare_session_results(app, EXERCISE_SUN_SALUTATION, 6, 0,
NULL, NULL, 0,
"db:screenshot-sun-salutation");
app->session_result.mood = 4;
} else if(activity == EXERCISE_PATTERNS) {
app_prepare_session_results(app, EXERCISE_PATTERNS, 8 * 60, 48,
"4-7-8", NULL, 0,
"db:screenshot-patterns");
app->session_result.mood = 5;
}
}
static void
setup_screenshot_scene(InbeApp *app, const ScreenshotRequest *request)
{
@@ -746,6 +785,8 @@ setup_screenshot_scene(InbeApp *app, const ScreenshotRequest *request)
app->main_tab = APP_MAIN_TAB_PRACTICE;
app->exercise_type = EXERCISE_WIM_HOF;
app->inbe.screen = InbeScreenSession;
} else if(strcmp(request->scene, "wim_hof_results") == 0) {
screenshot_setup_result_scene(app, EXERCISE_WIM_HOF);
} else if(strcmp(request->scene, "meditation_session") == 0) {
const PracticeDefinition *practice;
@@ -754,6 +795,8 @@ setup_screenshot_scene(InbeApp *app, const ScreenshotRequest *request)
practice = practice_get(EXERCISE_MEDITATION);
if(practice != NULL && practice->start != NULL)
practice->start(app);
} else if(strcmp(request->scene, "meditation_results") == 0) {
screenshot_setup_result_scene(app, EXERCISE_MEDITATION);
} else if(strcmp(request->scene, "sun_salutation_session") == 0) {
const PracticeDefinition *practice;
@@ -762,6 +805,8 @@ setup_screenshot_scene(InbeApp *app, const ScreenshotRequest *request)
practice = practice_get(EXERCISE_SUN_SALUTATION);
if(practice != NULL && practice->start != NULL)
practice->start(app);
} else if(strcmp(request->scene, "sun_salutation_results") == 0) {
screenshot_setup_result_scene(app, EXERCISE_SUN_SALUTATION);
} else if(strcmp(request->scene, "calendar_meditation") == 0) {
app->main_tab = APP_MAIN_TAB_HABITS;
app->habits.screen_mode = HABITS_SCREEN_DETAIL;
@@ -818,6 +863,8 @@ setup_screenshot_scene(InbeApp *app, const ScreenshotRequest *request)
app->exercise_type = EXERCISE_PATTERNS;
app->main_tab = APP_MAIN_TAB_PRACTICE;
patterns_practice_start(app);
} else if(strcmp(request->scene, "patterns_results") == 0) {
screenshot_setup_result_scene(app, EXERCISE_PATTERNS);
} else if(strcmp(request->scene, "patterns_config") == 0) {
app->exercise_type = EXERCISE_PATTERNS;
app->main_tab = APP_MAIN_TAB_PRACTICE;
@@ -95,12 +95,13 @@ meditation_start_configured :: (app: InbeApp*) {
}
finish :: (app: InbeApp*) #private {
app_notifications_send_session_complete(app)
duration: int
result_path: [FS_PATH_MAX] char = {0}
if app == nil {
return
}
app_notifications_send_session_complete(app)
duration = app->meditation.duration_seconds
if duration >= 60 {
@@ -110,8 +111,8 @@ finish :: (app: InbeApp*) #private {
1,
0,
EXERCISE_MEDITATION,
nil,
0) {
result_path,
sizeof(result_path)) {
sync_habits_for_activity(app, EXERCISE_MEDITATION)
app_auto_sync(app)
}
@@ -130,7 +131,9 @@ finish :: (app: InbeApp*) #private {
app->volume_popup_active = 0
meditation_music_stop(app)
practice_active_background_stop(app)
app_switch_screen(app, InbeScreenStart)
app_prepare_session_results(app, EXERCISE_MEDITATION, duration, 0, nil,
nil, 0, result_path)
app_switch_screen(app, InbeScreenResults)
}
timer_complete :: (app: InbeApp*) #private {
+9 -2
View File
@@ -162,19 +162,26 @@ phase_label_key :: (phase: int) -> const char* #private {
finish_session :: (app: InbeApp*) #private {
duration := app->patterns.elapsed_seconds
result_path: [FS_PATH_MAX] char = {0}
ratio_text: [32] char = {0}
app->patterns.active = 0
app->patterns.paused = 0
if duration >= 60 {
if data_save_session_path_for_activity(&duration, 1, 0,
EXERCISE_PATTERNS,
nil, 0) {
result_path,
sizeof(result_path)) {
sync_habits_for_activity(app, EXERCISE_PATTERNS)
app_auto_sync(app)
}
}
patterns_ratio_text(app, ratio_text, sizeof(ratio_text))
app_play_bell_cue(app, 1.0)
app_switch_screen(app, InbeScreenStart)
app_prepare_session_results(app, EXERCISE_PATTERNS, duration,
app->patterns.cycle, ratio_text, nil, 0,
result_path)
app_switch_screen(app, InbeScreenResults)
}
handle_exit_modal :: (app: InbeApp*) -> int #private {
+437 -2
View File
@@ -4,6 +4,9 @@
#import "practices/patterns/patterns_practice.h"
#import "practices/whm/whm_practice.h"
#import "practices/whm/whm_session.h"
#import "data.h"
#import "stdio.h"
#import "string.h"
ANDROID :: ANDROID_BUILD
@@ -22,6 +25,10 @@ PracticeId :: enum {
PRACTICE_COUNT = 4
}
#enum {
SESSION_RESULT_MOOD_COUNT = 5
}
PracticeVoidFn :: void (*)(InbeApp*) #type
PracticeCloseManualFn :: void (*)(InbeApp*, int) #type
PracticeDrawSessionFn :: void (*)(InbeApp*, int, int) #type
@@ -304,6 +311,434 @@ practice_update_active_breathing :: (app: InbeApp*, center_x: int, center_y: int
session_update_screen(app, center_x, center_y, hover)
}
practice_draw_results :: (app: InbeApp*, center_x: int, center_y: int, hover: int*) {
session_draw_results_screen(app, center_x, center_y, hover)
session_result_format_duration :: (seconds: int, out: char*, out_size: size_t) #private {
if out == nil || out_size == 0 {
return
}
if seconds < 0 {
seconds = 0
}
if seconds >= 3600 {
snprintf(out, out_size, "%dh %02dm", seconds / 3600,
(seconds % 3600) / 60)
} else if seconds >= 60 {
snprintf(out, out_size, "%dm %02ds", seconds / 60, seconds % 60)
} else {
snprintf(out, out_size, "%ds", seconds)
}
}
app_prepare_session_results :: (app: InbeApp*, activity: int,
primary_value: int, secondary_value: int,
detail: const char*, round_values: const int*,
round_count: int, saved_path: const char*) {
result: InbeSessionResult*
if app == nil {
return
}
result = &app->session_result
memset(result, 0, sizeof(*result))
result->active = 1
result->activity = practice_clamp_id(activity)
result->primary_value = primary_value
result->secondary_value = secondary_value
if detail != nil {
snprintf(result->detail, sizeof(result->detail), "%s", detail)
}
if round_values != nil && round_count > 0 {
if round_count > MaxRounds {
round_count = MaxRounds
}
result->round_count = round_count
for int i = 0; i < round_count; i++ {
result->round_values[i] = round_values[i]
}
}
if saved_path != nil && saved_path[0] != '\0' {
result->saved = 1
snprintf(result->path, sizeof(result->path), "%s", saved_path)
}
}
session_result_discard :: (app: InbeApp*) #private {
if app == nil {
return
}
if app->session_result.saved && app->session_result.path[0] != '\0' {
data_discard_session(app->session_result.path)
}
memset(&app->session_result, 0, sizeof(app->session_result))
app_switch_screen(app, InbeScreenStart)
}
session_result_done :: (app: InbeApp*) #private {
checkin: InbeStorageSessionCheckin = {0}
if app == nil {
return
}
if app->session_result.saved && app->session_result.path[0] != '\0' &&
app->session_result.mood > 0 {
checkin.mood_after = app->session_result.mood
data_save_session_checkin(app->session_result.path, &checkin)
}
memset(&app->session_result, 0, sizeof(app->session_result))
app_switch_screen(app, InbeScreenStart)
}
session_result_draw_pixel :: (x: int, y: int, w: int, h: int,
color: Color) #private {
DrawRectangle(x, y, w, h, color)
}
session_result_text_for_background :: (background: Color) -> Color #private {
luma: int = background.r * 299 + background.g * 587 + background.b * 114
return luma >= 128000 ? BLACK : WHITE
}
session_result_mood_color :: (mood: int) -> Color #private {
if mood <= 1 {
return (Color){226, 83, 78, 255}
} else if mood == 2 {
return (Color){238, 139, 70, 255}
} else if mood == 3 {
return (Color){235, 202, 77, 255}
} else if mood == 4 {
return (Color){108, 199, 104, 255}
}
return (Color){73, 194, 192, 255}
}
session_result_draw_mood_face :: (mood: int, cx: int, cy: int,
size: int, selected: int) #private {
unit := size / 12
if unit < 2 {
unit = 2
}
face := unit * 12
x := cx - face / 2
y := cy - face / 2
fill := session_result_mood_color(mood)
stroke := DarkenUIColor(fill, 45)
detail := (Color){38, 40, 48, 255}
shine := (Color){255, 255, 255, 170}
unused selected
DrawRectangle(x + unit * 3, y, unit * 6, unit, stroke)
DrawRectangle(x + unit * 2, y + unit, unit * 8, unit, stroke)
DrawRectangle(x + unit, y + unit * 2, unit * 10, unit, stroke)
DrawRectangle(x, y + unit * 3, unit * 12, unit * 6, stroke)
DrawRectangle(x + unit, y + unit * 9, unit * 10, unit, stroke)
DrawRectangle(x + unit * 2, y + unit * 10, unit * 8, unit, stroke)
DrawRectangle(x + unit * 3, y + unit * 11, unit * 6, unit, stroke)
DrawRectangle(x + unit * 3, y + unit, unit * 6, unit, fill)
DrawRectangle(x + unit * 2, y + unit * 2, unit * 8, unit, fill)
DrawRectangle(x + unit, y + unit * 3, unit * 10, unit * 6, fill)
DrawRectangle(x + unit * 2, y + unit * 9, unit * 8, unit, fill)
DrawRectangle(x + unit * 3, y + unit * 10, unit * 6, unit, fill)
session_result_draw_pixel(x + unit * 3, y + unit * 2, unit * 2, unit, shine)
if mood <= 1 {
session_result_draw_pixel(x + unit * 2, y + unit * 3, unit * 3, unit, detail)
session_result_draw_pixel(x + unit * 7, y + unit * 3, unit * 3, unit, detail)
session_result_draw_pixel(x + unit * 3, y + unit * 4, unit, unit, detail)
session_result_draw_pixel(x + unit * 8, y + unit * 4, unit, unit, detail)
session_result_draw_pixel(x + unit * 3, y + unit * 8, unit, unit, detail)
session_result_draw_pixel(x + unit * 4, y + unit * 7, unit * 4, unit, detail)
session_result_draw_pixel(x + unit * 8, y + unit * 8, unit, unit, detail)
} else if mood == 2 {
session_result_draw_pixel(x + unit * 3, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 7, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 3, y + unit * 8, unit, unit, detail)
session_result_draw_pixel(x + unit * 4, y + unit * 7, unit * 4, unit, detail)
session_result_draw_pixel(x + unit * 8, y + unit * 8, unit, unit, detail)
} else if mood == 3 {
session_result_draw_pixel(x + unit * 3, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 7, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 3, y + unit * 8, unit * 6, unit, detail)
} else if mood == 4 {
session_result_draw_pixel(x + unit * 3, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 7, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 2, y + unit * 7, unit, unit, detail)
session_result_draw_pixel(x + unit * 3, y + unit * 8, unit * 6, unit, detail)
session_result_draw_pixel(x + unit * 9, y + unit * 7, unit, unit, detail)
} else {
session_result_draw_pixel(x + unit * 3, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 7, y + unit * 4, unit * 2, unit * 2, detail)
session_result_draw_pixel(x + unit * 3, y + unit * 7, unit * 6, unit * 3, detail)
session_result_draw_pixel(x + unit * 4, y + unit * 7, unit * 4, unit, WHITE)
session_result_draw_pixel(x + unit * 4, y + unit * 9, unit * 4, unit, (Color){236, 108, 128, 255})
}
}
session_result_draw_mood_picker :: (app: InbeApp*, x: int, y: int, w: int,
hover: int*) -> int #private {
title_h := ScaleUIPx(28)
button_h := ScaleUIPx(64)
gap := ScaleUIPx(8)
item_w := (w - gap * (SESSION_RESULT_MOOD_COUNT - 1)) /
SESSION_RESULT_MOOD_COUNT
mouse := GetScreenToWorld2D(GetMousePosition(), app->camera)
DrawLeftUIControlTextInRect(GetLocaleText("results_mood_title"),
(Rectangle){(float)x, (float)y,
(float)w, (float)title_h},
GetUIFontSize(),
DarkenUIColor(GetThemeText(), 20))
y += title_h + ScaleUIPx(8)
for int i = 0; i < SESSION_RESULT_MOOD_COUNT; i++ {
bx := x + i * (item_w + gap)
bw := i == SESSION_RESULT_MOOD_COUNT - 1 ? x + w - bx : item_w
bounds := (Rectangle){(float)bx, (float)y, (float)bw, (float)button_h}
active := CheckCollisionPointRec(mouse, bounds) &&
!UIInputCapturesClick(mouse)
selected := app->session_result.mood == i + 1
mood_color := session_result_mood_color(i + 1)
fill := selected ? LightenUIColor(GetThemeSurface(), 5)
: DarkenUIColor(GetThemeBackground(), 7)
border := selected ? GetThemeButton()
: Fade(GetThemeText(), 0.26f)
if active {
MarkUIClickable()
if UIHoverEffectsEnabled() {
fill = selected ? LightenUIColor(GetThemeSurface(), 10)
: DarkenUIColor(GetThemeBackground(), 3)
}
if IsMouseButtonReleased(MOUSE_BUTTON_LEFT) &&
!UIInputCapturesClick(mouse) {
app->session_result.mood = i + 1
}
if hover != nil {
*hover = 1
}
}
DrawRectangleRounded(bounds, 0.18f, 10, fill)
if selected {
DrawRectangleRounded(bounds, 0.18f, 10, Fade(mood_color, 0.16f))
} else if active && UIHoverEffectsEnabled() {
DrawRectangleRounded(bounds, 0.18f, 10,
Fade(GetThemeButtonHover(), 0.08f))
}
DrawRectangleRoundedLinesEx(bounds, 0.18f, 10,
selected ? (float)ScaleUIPx(2) : 1.0f,
border)
session_result_draw_mood_face(i + 1, bx + bw / 2,
y + button_h / 2,
ScaleUIPx(32), selected)
}
return title_h + ScaleUIPx(8) + button_h
}
practice_draw_results :: (app: InbeApp*, center_x: int, center_y: int, hover: int*) {
result: InbeSessionResult*
box_x: int
box_w: int
title_font: int
title_w: int
summary_rows: [8] UIInfoRow
summary_text: [8][80] char
summary_count: int
row_y: int
content_top: int = ScaleUIPx(82)
done_hover: int = 0
discard_hover: int = 0
button_y: int
button_h: int
gap: int
button_w: int
unused center_y
if app == nil {
return
}
result = &app->session_result
if !result->active {
session_draw_results_screen(app, center_x, center_y, hover)
return
}
responsive_max_w: int = (int)(view_width * 0.94f)
if responsive_max_w < ScaleUIPx(300) {
responsive_max_w = ScaleUIPx(300)
}
if responsive_max_w > ScaleUIPx(520) {
responsive_max_w = ScaleUIPx(520)
}
GetUICenteredColumn(responsive_max_w, GetUIPageSidePadding(), &box_x, &box_w)
title_font = GetUITitleFontSize(GetLocaleText("results_title"),
view_width - ScaleUIPx(48))
title_w = TextWidth(GetLocaleText("results_title"), title_font)
Text(GetLocaleText("results_title"), center_x - title_w / 2,
ScaleUIPx(28), title_font, GetThemeText())
summary_count = 0
snprintf(summary_text[summary_count], sizeof(summary_text[summary_count]),
"%s", practice_label(result->activity))
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(), GetThemeText()}
summary_count++
if result->activity == EXERCISE_WIM_HOF {
total := 0
best := 0
avg := 0
for int i = 0; i < result->round_count; i++ {
seconds := result->round_values[i]
total += seconds
if seconds > best {
best = seconds
}
}
avg = result->round_count > 0 ? total / result->round_count : 0
FormatLocaleText(summary_text[summary_count],
sizeof(summary_text[summary_count]),
"results_rounds", result->round_count)
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(),
GetThemeText()}
summary_count++
FormatLocaleText(summary_text[summary_count],
sizeof(summary_text[summary_count]),
"results_best", best)
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(),
GetThemeText()}
summary_count++
FormatLocaleText(summary_text[summary_count],
sizeof(summary_text[summary_count]),
"results_avg", avg)
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(),
GetThemeText()}
summary_count++
} else if result->activity == EXERCISE_MEDITATION ||
result->activity == EXERCISE_PATTERNS {
duration: [32] char
session_result_format_duration(result->primary_value, duration,
sizeof(duration))
FormatLocaleText(summary_text[summary_count],
sizeof(summary_text[summary_count]),
"results_duration", duration)
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(),
GetThemeText()}
summary_count++
if result->activity == EXERCISE_PATTERNS && result->detail[0] != '\0' {
FormatLocaleText(summary_text[summary_count],
sizeof(summary_text[summary_count]),
"results_pattern", result->detail)
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(),
GetThemeText()}
summary_count++
}
if result->activity == EXERCISE_PATTERNS && result->secondary_value > 0 {
FormatLocaleText(summary_text[summary_count],
sizeof(summary_text[summary_count]),
"results_cycles", result->secondary_value)
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(),
GetThemeText()}
summary_count++
}
} else if result->activity == EXERCISE_SUN_SALUTATION {
FormatLocaleText(summary_text[summary_count],
sizeof(summary_text[summary_count]),
"results_repetitions", result->primary_value)
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
GetUIFontSize(),
GetThemeText()}
summary_count++
}
snprintf(summary_text[summary_count], sizeof(summary_text[summary_count]),
"%s", GetLocaleText(result->saved ? "results_saved_status"
: "results_unsaved_status"))
summary_rows[summary_count] = (UIInfoRow){summary_text[summary_count],
Text16,
DarkenUIColor(GetThemeText(), 18)}
summary_count++
InfoRows((InfoRowsProps){
.x = box_x,
.y = content_top,
.width = box_w,
.row_height = ScaleUIPx(31),
.rows = summary_rows,
.row_count = summary_count,
.background = DarkenUIColor(GetThemeBackground(), 6),
.separator = DarkenUIColor(GetThemeBackground(), 30),
.default_text = GetThemeText()
})
row_y = content_top + summary_count * ScaleUIPx(31) + ScaleUIPx(18)
row_y += session_result_draw_mood_picker(app, box_x, row_y, box_w, hover)
row_y += ScaleUIPx(18)
if result->activity == EXERCISE_WIM_HOF && result->round_count > 0 {
round_gap := ScaleUIPx(8)
round_col_w := (box_w - round_gap) / 2
round_h := ScaleUIPx(27)
DrawLeftUIControlTextInRect(GetLocaleText("round_times_title"),
(Rectangle){(float)box_x, (float)row_y,
(float)box_w, (float)ScaleUIPx(26)},
GetUIFontSize(),
DarkenUIColor(GetThemeText(), 20))
row_y += ScaleUIPx(30)
for int i = 0; i < result->round_count; i++ {
row: [48] char
col := i % 2
grid_row := i / 2
cell_x := box_x + col * (round_col_w + round_gap)
cell_y := row_y + grid_row * (round_h + round_gap)
FormatLocaleText(row, sizeof(row), "round_result_label", i + 1,
result->round_values[i])
DrawRectangle(cell_x, cell_y, round_col_w, round_h,
DarkenUIColor(GetThemeBackground(), 4))
DrawLeftUIControlTextInRect(row,
(Rectangle){(float)(cell_x + ScaleUIPx(12)),
(float)cell_y,
(float)(round_col_w - ScaleUIPx(24)),
(float)round_h},
Text16, GetThemeText())
}
row_y += ((result->round_count + 1) / 2) * (round_h + round_gap) +
ScaleUIPx(16)
}
button_h = ScaleUIPx(46)
gap = ScaleUIPx(12)
button_y = view_height - ScaleUIPx(28) - button_h
if result->saved {
button_w = (box_w - gap) / 2
if StyledButton(box_x, button_y, button_w, button_h,
GetLocaleText("discard_button"),
ButtonStyleSecondary, 0, &discard_hover) {
session_result_discard(app)
}
if StyledButton(box_x + button_w + gap, button_y,
box_w - button_w - gap, button_h,
GetLocaleText("done_button"),
ButtonStylePrimary, 0, &done_hover) {
session_result_done(app)
}
} else {
if StyledButton(box_x, button_y, box_w, button_h,
GetLocaleText("done_button"),
ButtonStylePrimary, 0, &done_hover) {
session_result_done(app)
}
}
if hover != nil && (done_hover || discard_hover) {
*hover = 1
}
}
@@ -2,6 +2,7 @@
#import "app.h"
#import "data.h"
#import "practices/meditation/meditation_music.h"
#import "practices/practice_registry.h"
#import "practices/sun_salutation/sun_salutation_practice.h"
#import "stdio.h"
@@ -20,12 +21,13 @@ exit_to_start :: (app: InbeApp*) #private {
}
finish :: (app: InbeApp*) #private {
app_notifications_send_session_complete(app)
repetitions := 0
result_path: [FS_PATH_MAX] char = {0}
if app == nil {
return
}
app_notifications_send_session_complete(app)
repetitions = app->sun_salutation.repetitions
if repetitions < 1 {
@@ -33,11 +35,19 @@ finish :: (app: InbeApp*) #private {
}
if data_save_session_path_for_activity(&repetitions, 1, 0,
EXERCISE_SUN_SALUTATION,
nil, 0) {
result_path, sizeof(result_path)) {
sync_habits_for_activity(app, EXERCISE_SUN_SALUTATION)
app_auto_sync(app)
}
exit_to_start(app)
app->sun_salutation.step = 0
app->sun_salutation.repetition = 0
app->sun_salutation.step_ticks = 0
app->session_paused = 0
meditation_music_stop(app)
app_close_modal(app)
app_prepare_session_results(app, EXERCISE_SUN_SALUTATION, repetitions, 0,
nil, nil, 0, result_path)
app_switch_screen(app, InbeScreenResults)
}
sun_salutation_practice_start :: (app: InbeApp*) {
+4
View File
@@ -465,12 +465,16 @@ finish_round :: (app: InbeApp*) #private {
session_complete :: (app: InbeApp*) #private {
if session_ensure_results_saved(app) {
round_times: [MaxRounds] int
rounds := collect_result_rounds(app, round_times, MaxRounds)
meditation_music_stop(app)
#if ANDROID {
android_allow_screen_off()
stop_android_background_session(app)
}
app_notifications_send_session_complete(app)
app_prepare_session_results(app, EXERCISE_WIM_HOF, 0, 0, nil,
round_times, rounds, app->results_path)
app_switch_screen(app, InbeScreenResults)
} else {
app_init(app)
+110 -4
View File
@@ -22,6 +22,7 @@ StatisticsGraphPoint :: struct {
StatisticsScrollPageContext :: struct {
linked_count: int
mood_count: int
}
statistics_day_count :: (habit: const InbeHabit*, linked_ctx: const HabitLinkedContext*, day_index: int) -> int {
@@ -119,6 +120,90 @@ statistics_draw_section_title :: (title: const char*, x: int, y: int, w: int) ->
return height
}
statistics_mood_color :: (mood: int) -> Color #private {
if mood <= 1 {
return (Color){226, 83, 78, 255}
} else if mood == 2 {
return (Color){238, 139, 70, 255}
} else if mood == 3 {
return (Color){235, 202, 77, 255}
} else if mood == 4 {
return (Color){108, 199, 104, 255}
}
return (Color){73, 194, 192, 255}
}
statistics_format_average :: (out: char*, out_size: size_t, value_x100: int,
suffix: const char*) #private {
sign: [2] char = {0}
value := value_x100
if out == nil || out_size == 0 {
return
}
if value < 0 {
sign[0] = '-'
value = -value
}
snprintf(out, out_size, "%s%d.%02d%s", sign, value / 100, value % 100,
suffix != nil ? suffix : "")
}
statistics_draw_mood_panel :: (content_x: int, y: int, content_w: int,
stats: const InbeStorageMoodStats*,
accent: Color) -> int #private {
panel_h := ScaleUIPx(156)
metrics_gap := ScaleUIPx(8)
metric_h := ScaleUIPx(58)
metric_w := (content_w - metrics_gap) / 2
bars_y := y + ScaleUIPx(78)
bars_h := ScaleUIPx(54)
slot_w := content_w / 5
value: [32] char = {0}
if stats == nil || stats->total <= 0 {
return 0
}
y += statistics_draw_section_title(GetLocaleText("habit_stats_mood_title"),
content_x, y, content_w) + ScaleUIPx(10)
statistics_format_average(value, sizeof(value), stats->average_after_x100,
"/5")
statistics_draw_metric(content_x, y, metric_w, metric_h,
GetLocaleText("habit_stats_mood_average"), value,
accent)
snprintf(value, sizeof(value), "%d", stats->total)
statistics_draw_metric(content_x + metric_w + metrics_gap, y,
content_w - metric_w - metrics_gap, metric_h,
GetLocaleText("habit_stats_mood_checkins"), value,
LightenUIColor(accent, 20))
DrawRectangle(content_x, bars_y, content_w, bars_h,
DarkenUIColor(GetThemeBackground(), 7))
for int i = 0; i < 5; i++ {
count := stats->counts[i]
bar_h := count > 0 ? (count * (bars_h - ScaleUIPx(24))) / stats->total
: ScaleUIPx(3)
x := content_x + i * slot_w + ScaleUIPx(7)
w := slot_w - ScaleUIPx(14)
bar_y := bars_y + bars_h - bar_h - ScaleUIPx(18)
label: [4] char = {0}
if w < ScaleUIPx(4) {
w = ScaleUIPx(4)
}
DrawRectangle(x, bar_y, w, bar_h,
count > 0 ? statistics_mood_color(i + 1)
: DarkenUIColor(GetThemeBackground(), 24))
snprintf(label, sizeof(label), "%d", i + 1)
Text(label, x + (w - TextWidth(label, Text12)) / 2,
bars_y + bars_h - ScaleUIPx(16), Text12,
DarkenUIColor(GetThemeText(), 18))
}
return panel_h
}
statistics_draw_hold_range_selector :: (app: InbeApp*, x: int, y: int, w: int) -> int #private {
labels: [2] const char* = {"1W", "1M"}
values: [2] const int = {7, 31}
@@ -163,15 +248,16 @@ statistics_draw_hold_range_selector :: (app: InbeApp*, x: int, y: int, w: int) -
return clicked
}
statistics_content_height :: (linked_count: int) -> int #private {
return ScaleUIPx(linked_count > 0 ? 710 : 420)
statistics_content_height :: (linked_count: int, mood_count: int) -> int #private {
return ScaleUIPx(linked_count > 0 ? 710 : 420) +
(mood_count > 0 ? ScaleUIPx(188) : 0)
}
statistics_scroll_page_content_height :: (content_w: int, user_data: void*) -> int #private {
ctx := (StatisticsScrollPageContext*)user_data
unused content_w
return statistics_content_height(ctx->linked_count)
return statistics_content_height(ctx->linked_count, ctx->mood_count)
}
statistics_draw_hold_graph :: (app: InbeApp*, linked_ctx: const HabitLinkedContext*, content_x: int, y: int, content_w: int, today_tm: const struct tm*, filter: int, accent: Color) #private {
@@ -332,6 +418,13 @@ statistics_draw_view :: (app: InbeApp*, active: InbeHabit*, linked_ctx: HabitLin
metric_w := 0
value: [64] char = {0}
has_wim_hof_rounds := statistics_has_wim_hof_rounds(linked_ctx)
mood_stats: InbeStorageMoodStats = {0}
mood_count := 0
if active != nil && active->sync_mode == INBE_HABIT_SYNC_ACTIVITIES &&
active->sync_activity != 0 {
mood_count = storage_mood_stats(active->sync_activity, 0, &mood_stats)
}
if now_tm != NULL {
today_tm = *now_tm
@@ -391,6 +484,11 @@ statistics_draw_view :: (app: InbeApp*, active: InbeHabit*, linked_ctx: HabitLin
statistics_draw_metric(content_x + metric_w + metrics_gap, y, content_w - metric_w - metrics_gap, metric_h, GetLocaleText("habit_stats_last_30_days"), value, LightenUIColor(active->color, 24))
y += metric_h + ScaleUIPx(22)
if mood_count > 0 {
y += statistics_draw_mood_panel(content_x, y, content_w, &mood_stats,
active->color) + ScaleUIPx(22)
}
if has_wim_hof_rounds {
y += statistics_draw_section_title(GetLocaleText("habit_stats_wim_hof_hold_rounds"), content_x, y, content_w) + ScaleUIPx(10)
statistics_draw_hold_range_selector(app, content_x, y, ScaleUIPx(118))
@@ -447,6 +545,8 @@ draw_statistics_content :: (app: InbeApp*, content_top: int) {
linked_ctx := (HabitLinkedContext*)NULL
page_ctx := (StatisticsScrollPageContext){0}
page := (UIScrollPage){0}
page_mood_stats: InbeStorageMoodStats = {0}
page_mood_count := 0
if app->habits.count <= 0 {
return
@@ -466,7 +566,13 @@ draw_statistics_content :: (app: InbeApp*, content_top: int) {
if scroll_h < 0 {
scroll_h = 0
}
page_ctx = (StatisticsScrollPageContext){linked_ctx != NULL ? linked_ctx->count : 0}
if active != NULL && active->sync_mode == INBE_HABIT_SYNC_ACTIVITIES &&
active->sync_activity != 0 {
page_mood_count = storage_mood_stats(active->sync_activity, 0,
&page_mood_stats)
}
page_ctx.linked_count = linked_ctx != NULL ? linked_ctx->count : 0
page_ctx.mood_count = page_mood_count
page = BeginUIScrollPage((UIScrollPageSpec){.y = scroll_y, .height = scroll_h, .max_content_width = max_w, .scroll_offset = &app->habits.scroll, .content_height = statistics_scroll_page_content_height, .user_data = &page_ctx})
statistics_draw_view(app, active, linked_ctx, page.content_x, page.content_w, page.content_y + ScaleUIPx(8))
EndUIScrollPage(page)
+3
View File
@@ -3,6 +3,7 @@
#include <stddef.h>
#include "core/breath_engine.h"
#include "storage.h"
typedef enum DataImportMode {
DATA_IMPORT_DATA_ONLY = 0,
@@ -30,6 +31,8 @@ int data_replace_session(const char *path, const int *round_times, int round_cou
int data_rename_session(const char *old_path, const char *new_path);
int data_delete_session(const char *path);
int data_discard_session(const char *path);
int data_save_session_checkin(const char *path,
const InbeStorageSessionCheckin *checkin);
int data_has_any(void);
long long data_get_total_size(void);
int data_get_session_count(void);
+6
View File
@@ -176,6 +176,12 @@ data_discard_session :: (path: const char*) -> int {
return storage_discard_session(path)
}
data_save_session_checkin :: (path: const char*,
checkin: const InbeStorageSessionCheckin*) -> int {
data_init()
return storage_save_session_checkin(path, checkin)
}
data_has_any :: () -> int {
data_init()
return storage_has_any()
+30
View File
@@ -263,6 +263,12 @@ schema_create :: () -> int #export {
" source TEXT NOT NULL,"
" imported_at INTEGER NOT NULL,"
" rounds_hash INTEGER NOT NULL,"
" mood_before INTEGER NOT NULL DEFAULT 0,"
" mood_after INTEGER NOT NULL DEFAULT 0,"
" energy INTEGER NOT NULL DEFAULT 0,"
" stress INTEGER NOT NULL DEFAULT 0,"
" note TEXT NOT NULL DEFAULT '',"
" tags TEXT NOT NULL DEFAULT '',"
" deleted_at INTEGER NOT NULL DEFAULT 0,"
" updated_at INTEGER NOT NULL DEFAULT 0,"
" UNIQUE(user_id,started_at,rounds_hash)"
@@ -553,6 +559,30 @@ migrate_schema :: () -> int #export {
return 0
}
}
if !table_has_column("sessions", "mood_before") &&
!exec_sql("ALTER TABLE sessions ADD COLUMN mood_before INTEGER NOT NULL DEFAULT 0") {
return 0
}
if !table_has_column("sessions", "mood_after") &&
!exec_sql("ALTER TABLE sessions ADD COLUMN mood_after INTEGER NOT NULL DEFAULT 0") {
return 0
}
if !table_has_column("sessions", "energy") &&
!exec_sql("ALTER TABLE sessions ADD COLUMN energy INTEGER NOT NULL DEFAULT 0") {
return 0
}
if !table_has_column("sessions", "stress") &&
!exec_sql("ALTER TABLE sessions ADD COLUMN stress INTEGER NOT NULL DEFAULT 0") {
return 0
}
if !table_has_column("sessions", "note") &&
!exec_sql("ALTER TABLE sessions ADD COLUMN note TEXT NOT NULL DEFAULT ''") {
return 0
}
if !table_has_column("sessions", "tags") &&
!exec_sql("ALTER TABLE sessions ADD COLUMN tags TEXT NOT NULL DEFAULT ''") {
return 0
}
if !exec_sql(
"CREATE TABLE IF NOT EXISTS sync_outbox("
" seq INTEGER PRIMARY KEY AUTOINCREMENT,"
+23 -4
View File
@@ -992,7 +992,7 @@ storage_append_session_row_json(JsonBuilder *json, sqlite3_stmt *stmt)
{
const char *id = (const char *)sqlite3_column_text(stmt, 0);
long long started_at = sqlite3_column_int64(stmt, 1);
long long updated_at = sqlite3_column_int64(stmt, 8);
long long updated_at = sqlite3_column_int64(stmt, 14);
json_append(json, "{");
json_append_key_string(json, "id", id);
@@ -1004,7 +1004,15 @@ storage_append_session_row_json(JsonBuilder *json, sqlite3_stmt *stmt)
json_append_key_string(json, "source", (const char *)sqlite3_column_text(stmt, 5));
json_append(json, ",");
json_append_key_string(json, "rounds_hash", (const char *)sqlite3_column_text(stmt, 6));
json_appendf(json, ",\"deleted_at\":%lld,\"updated_at\":", sqlite3_column_int64(stmt, 7));
json_appendf(json,
",\"mood_before\":%d,\"mood_after\":%d,\"energy\":%d,"
"\"stress\":%d,",
sqlite3_column_int(stmt, 7), sqlite3_column_int(stmt, 8),
sqlite3_column_int(stmt, 9), sqlite3_column_int(stmt, 10));
json_append_key_string(json, "note", (const char *)sqlite3_column_text(stmt, 11));
json_append(json, ",");
json_append_key_string(json, "tags", (const char *)sqlite3_column_text(stmt, 12));
json_appendf(json, ",\"deleted_at\":%lld,\"updated_at\":", sqlite3_column_int64(stmt, 13));
json_append_epoch(json, updated_at > 0 ? updated_at : started_at);
json_append(json, ",");
storage_append_session_rounds_json(json, id);
@@ -1088,7 +1096,8 @@ storage_append_session_payload_json(JsonBuilder *json, const char *session_id)
json,
"SELECT "
"id,started_at,local_date,topic,activity,source,"
"rounds_hash,deleted_at,updated_at "
"rounds_hash,mood_before,mood_after,energy,stress,note,tags,"
"deleted_at,updated_at "
"FROM sessions WHERE user_id=?1 AND id=?2",
session_id, storage_append_session_row_json);
}
@@ -2022,7 +2031,8 @@ storage_apply_sync_sessions_json(const char *response_json)
static const char *sessions_sql =
"INSERT INTO "
"sessions(id,user_id,started_at,local_date,topic,activity,source,"
"imported_at,rounds_hash,deleted_at,updated_at) "
"imported_at,rounds_hash,mood_before,mood_after,energy,stress,note,tags,"
"deleted_at,updated_at) "
"SELECT COALESCE(json_extract(value,'$.id'),''),?2,"
" "
"CAST(COALESCE(strftime('%s',json_extract(value,'$.started_at')),'0') AS "
@@ -2035,6 +2045,12 @@ storage_apply_sync_sessions_json(const char *response_json)
"CAST(COALESCE(strftime('%s',json_extract(value,'$.updated_at')),"
"strftime('%s',json_extract(value,'$.started_at')),'0') AS INTEGER),"
" CAST(COALESCE(json_extract(value,'$.rounds_hash'),0) AS INTEGER),"
" CAST(COALESCE(json_extract(value,'$.mood_before'),0) AS INTEGER),"
" CAST(COALESCE(json_extract(value,'$.mood_after'),0) AS INTEGER),"
" CAST(COALESCE(json_extract(value,'$.energy'),0) AS INTEGER),"
" CAST(COALESCE(json_extract(value,'$.stress'),0) AS INTEGER),"
" COALESCE(json_extract(value,'$.note'),''),"
" COALESCE(json_extract(value,'$.tags'),''),"
" CAST(COALESCE(json_extract(value,'$.deleted_at'),0) AS INTEGER),"
" "
"CAST(COALESCE(strftime('%s',json_extract(value,'$.updated_at')),"
@@ -2047,6 +2063,9 @@ storage_apply_sync_sessions_json(const char *response_json)
"excluded.local_date,"
" topic=excluded.topic,activity=excluded.activity,source=excluded.source,"
" imported_at=excluded.imported_at,rounds_hash=excluded.rounds_hash,"
" mood_before=excluded.mood_before,mood_after=excluded.mood_after,"
" energy=excluded.energy,stress=excluded.stress,note=excluded.note,"
" tags=excluded.tags,"
"deleted_at=excluded.deleted_at,"
" updated_at=excluded.updated_at "
"WHERE excluded.updated_at > sessions.updated_at "
+24
View File
@@ -10,6 +10,24 @@ enum {
INBE_SYNC_PROTOCOL_VERSION = 3
};
typedef struct InbeStorageSessionCheckin {
int mood_before;
int mood_after;
int energy;
int stress;
char note[256];
char tags[160];
} InbeStorageSessionCheckin;
typedef struct InbeStorageMoodStats {
int total;
int counts[5];
int average_after_x100;
int average_lift_x100;
int average_energy_x100;
int average_stress_x100;
} InbeStorageMoodStats;
typedef void (*InbeStorageSessionRecordCallback)(const char *id,
int year, int month, int day,
int hour, int minute, int second,
@@ -81,6 +99,12 @@ int storage_discard_session(const char *id);
int storage_load_session(const char *id, int *round_times, int max_rounds,
int *year, int *month, int *day,
int *hour, int *minute, int *second);
int storage_save_session_checkin(const char *id,
const InbeStorageSessionCheckin *checkin);
int storage_load_session_checkin(const char *id,
InbeStorageSessionCheckin *checkin);
int storage_mood_stats(int activity_mask, int days,
InbeStorageMoodStats *stats);
void storage_list_session_records(InbeStorageSessionRecordCallback callback, void *user);
int storage_has_any(void);
int storage_session_count(void);
+144
View File
@@ -281,6 +281,150 @@ storage_load_session :: (path_or_id: const char*, round_times: int*,
return count
}
storage_save_session_checkin :: (path_or_id: const char*,
checkin: const InbeStorageSessionCheckin*) -> int {
stmt: sqlite3_stmt* = nil
id: [INBE_STORAGE_ID_SIZE] char
if !parse_db_id(path_or_id, id, sizeof(id)) || checkin == nil {
return 0
}
if sqlite3_prepare_v2(g_storage.db,
"UPDATE sessions SET mood_before=?2,mood_after=?3,"
"energy=?4,stress=?5,note=?6,tags=?7,updated_at=?8 "
"WHERE id=?1 AND deleted_at=0",
-1, &stmt, nil) != SQLITE_OK {
return 0
}
bind_text(stmt, 1, id)
sqlite3_bind_int(stmt, 2, checkin->mood_before)
sqlite3_bind_int(stmt, 3, checkin->mood_after)
sqlite3_bind_int(stmt, 4, checkin->energy)
sqlite3_bind_int(stmt, 5, checkin->stress)
bind_text(stmt, 6, checkin->note)
bind_text(stmt, 7, checkin->tags)
sqlite3_bind_int64(stmt, 8, now_seconds())
sqlite3_step(stmt)
changed := sqlite3_changes(g_storage.db) > 0
sqlite3_finalize(stmt)
if changed {
storage_enqueue_sync_session(id)
storage_schedule_persist()
}
return changed
}
storage_load_session_checkin :: (path_or_id: const char*,
checkin: InbeStorageSessionCheckin*) -> int {
stmt: sqlite3_stmt* = nil
id: [INBE_STORAGE_ID_SIZE] char
if checkin != nil {
memset(checkin, 0, sizeof(*checkin))
}
if !parse_db_id(path_or_id, id, sizeof(id)) || checkin == nil {
return 0
}
if sqlite3_prepare_v2(g_storage.db,
"SELECT mood_before,mood_after,energy,stress,note,tags "
"FROM sessions WHERE id=?1 AND deleted_at=0",
-1, &stmt, nil) != SQLITE_OK {
return 0
}
bind_text(stmt, 1, id)
if sqlite3_step(stmt) != SQLITE_ROW {
sqlite3_finalize(stmt)
return 0
}
checkin->mood_before = sqlite3_column_int(stmt, 0)
checkin->mood_after = sqlite3_column_int(stmt, 1)
checkin->energy = sqlite3_column_int(stmt, 2)
checkin->stress = sqlite3_column_int(stmt, 3)
snprintf(checkin->note, sizeof(checkin->note), "%s",
sqlite3_column_text(stmt, 4) != nil
? (const char*)sqlite3_column_text(stmt, 4) : "")
snprintf(checkin->tags, sizeof(checkin->tags), "%s",
sqlite3_column_text(stmt, 5) != nil
? (const char*)sqlite3_column_text(stmt, 5) : "")
sqlite3_finalize(stmt)
return 1
}
storage_mood_stats :: (activity_mask: int, days: int,
stats: InbeStorageMoodStats*) -> int {
stmt: sqlite3_stmt* = nil
cutoff: long long = 0
after_total: long long = 0
lift_total: long long = 0
energy_total: long long = 0
stress_total: long long = 0
lift_count: int = 0
energy_count: int = 0
stress_count: int = 0
if stats != nil {
memset(stats, 0, sizeof(*stats))
}
if g_storage.db == nil || stats == nil {
return 0
}
if days > 0 {
cutoff = now_seconds() - (long long)days * 86400
}
if sqlite3_prepare_v2(g_storage.db,
"SELECT mood_before,mood_after,energy,stress "
"FROM sessions WHERE user_id=?1 AND deleted_at=0 "
"AND mood_after BETWEEN 1 AND 5 "
"AND (?2=0 OR (activity>=0 AND activity<30 "
"AND ((1 << activity) & ?2)<>0)) "
"AND (?3=0 OR started_at>=?3)",
-1, &stmt, nil) != SQLITE_OK {
return 0
}
bind_text(stmt, 1, g_storage.user_id)
sqlite3_bind_int(stmt, 2, activity_mask)
sqlite3_bind_int64(stmt, 3, cutoff)
while sqlite3_step(stmt) == SQLITE_ROW {
before := sqlite3_column_int(stmt, 0)
after := sqlite3_column_int(stmt, 1)
energy := sqlite3_column_int(stmt, 2)
stress := sqlite3_column_int(stmt, 3)
if after < 1 || after > 5 {
continue
}
stats->counts[after - 1]++
stats->total++
after_total += after
if before >= 1 && before <= 5 {
lift_total += after - before
lift_count++
}
if energy >= 1 && energy <= 5 {
energy_total += energy
energy_count++
}
if stress >= 1 && stress <= 5 {
stress_total += stress
stress_count++
}
}
sqlite3_finalize(stmt)
if stats->total > 0 {
stats->average_after_x100 = (int)((after_total * 100) / stats->total)
}
if lift_count > 0 {
stats->average_lift_x100 = (int)((lift_total * 100) / lift_count)
}
if energy_count > 0 {
stats->average_energy_x100 = (int)((energy_total * 100) / energy_count)
}
if stress_count > 0 {
stats->average_stress_x100 = (int)((stress_total * 100) / stress_count)
}
return stats->total
}
storage_replace_session :: (path_or_id: const char*, round_times: const int*,
round_count: int) -> int {
stmt: sqlite3_stmt* = nil
+1 -1