Skip to content

Commit

Permalink
implemented number of days for model creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pail23 committed Jan 4, 2024
1 parent 3956463 commit e8d09ea
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/api/energyAssistant.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ export class EnergyAssistantApi {
return (await this.axiosInstance.get<IForecast>('forecast')).data;
}

public async createModel() {
public async createModel(daysToRetreive: number) {
if (!this.axiosInstance) throw 'not initialized';
return await this.axiosInstance.post<ICreateForecastModel>(
'forecast/create_model',
'forecast/create_model?days_to_retrieve=' + daysToRetreive,
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@
"forecast": "Vorhersage",
"core": "Energy Assistant",
"forecast_create_model": "Vorhersagemodell erzeugen",
"forecast_create_model_text": "Erzuege das Vorhersagemodell für den Energieverbrauch basierend auf den historischen Daten aus Homeassistant.",
"forecast_create_model_text": "Erzeuge das Vorhersagemodell für den Energieverbrauch basierend auf den historischen Daten aus Homeassistant.",
"forecast_create": "Erzeugen",
"forecast_tune_model": "Vorhersagemodell optimieren",
"forecast_tune_model_text": "Optimiere das Vorhersagemodell. Dieser Vorgang kann einige Zeit dauern.",
"forecast_tune": "Optimieren",
"forecast_r2score": "Der R2 Wert des Modells ist",
"delete_action": "Löschen"
"delete_action": "Löschen",
"forecast_create_model_error": "Das Model konnte nicht erstellt werden. Homeassistant hat wahrscheinlich nicht genügend Daten.",
"forecast_value_too_small": "Der Wert ist zu klein.",
"forecast_field_required": "Bitte einen Wert eingeben."
}
}
7 changes: 5 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@
"forecast_create_model_text": "Create the load forcast model based on historical data.",
"forecast_create": "Create",
"forecast_tune_model": "Tune forecast model",
"forecast_tune_model_text": " Tune the load forcast model in order to optimize the forecast quality. This might take some time.",
"forecast_tune_model_text": "Tune the load forcast model in order to optimize the forecast quality. This might take some time.",
"forecast_tune": "Tune",
"forecast_r2score": "Model R2 score is",
"delete_action": "Delete"
"delete_action": "Delete",
"forecast_create_model_error": "Failed to create the model. Homeassistant might not have enough data.",
"forecast_value_too_small": "The value is too small.",
"forecast_field_required": "Field is required"
}
}
32 changes: 26 additions & 6 deletions src/views/settings/Forecast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
<v-card class="m-4 max-w-sm elevation-6">
<v-card-title>{{ $t('settings.forecast_create_model') }}</v-card-title>
<v-card-item>
{{ $t('settings.forecast_create_model_text') }}
<div class="my-2">
{{ $t('settings.forecast_create_model_text') }}
</div>
<v-text-field
v-model="numberOfDays"
label="Anzahl Tage"
single-line
type="number"
:rules="dayRules"
/>
<v-progress-linear
v-if="isCreating"
indeterminate
Expand Down Expand Up @@ -49,16 +58,27 @@ const { t } = useI18n();
const isCreating = ref(false);
const isTuning = ref(false);
const r2Label = ref('');
const numberOfDays = ref(10);
const CreateModel = async function () {
isCreating.value = true;
const response = await api.createModel();
isCreating.value = false;
r2Label.value =
t('settings.forecast_r2score') + ' ' + response.data.r2.toFixed(2);
try {
const response = await api.createModel(numberOfDays.value);
r2Label.value =
t('settings.forecast_r2score') + ' ' + response.data.r2.toFixed(2);
} catch (error) {
r2Label.value = t('settings.forecast_create_model_error');
} finally {
isCreating.value = false;
}
};
const TuneModel = async function () {
const dayRules = [
(value) => !!value || t("settings.forecast_field_required"),
(value) => (!!value && value > 2) || t("settings.forecast_value_too_small"),
];
const TuneModel = async () => {
isTuning.value = true;
await api.tuneModel();
isTuning.value = false;
Expand Down

0 comments on commit e8d09ea

Please sign in to comment.