mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-21 05:58:23 +02:00
Merge pull request #140 from R0m1k3/1.1
Handle duplicate weather data entries and improve historical fetching
This commit is contained in:
3 files changed
+26
-11
No files matched your search
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
# https://curl.se/docs/http-cookies.html
|
# https://curl.se/docs/http-cookies.html
|
||||||
# This file was generated by libcurl! Edit at your own risk.
|
# This file was generated by libcurl! Edit at your own risk.
|
||||||
|
|
||||||
#HttpOnly_localhost FALSE / FALSE 1755332443 connect.sid s%3Ag_FLmIyfx_N-5QZpTU_E9Tq4Ex9FFnxY.A1JSe5Hq9weYwtimsv7bQq6FLWLDcH6CBt%2FeZnBzlus
|
#HttpOnly_localhost FALSE / FALSE 1755332748 connect.sid s%3ATGkcy9eVr4-9HEcJjuFU9AZrRq4VYOLY.TsQjtj4uhpU1n9T1IDgVMkeiQAi8SdziEoQFRooTS8w
|
||||||
+20
-4
@@ -2864,25 +2864,41 @@ RÉSUMÉ DU SCAN
|
|||||||
|
|
||||||
// Fetch current year data if not in cache
|
// Fetch current year data if not in cache
|
||||||
if (!currentYearData) {
|
if (!currentYearData) {
|
||||||
console.log("🌤️ Fetching current weather data from API");
|
console.log("🌤️ [FETCH] Fetching current weather data from API");
|
||||||
const apiData = await weatherService.fetchCurrentWeather(settings);
|
const apiData = await weatherService.fetchCurrentWeather(settings);
|
||||||
if (apiData) {
|
if (apiData) {
|
||||||
const weatherData = weatherService.convertApiDataToWeatherData(apiData, settings.location, true);
|
const weatherData = weatherService.convertApiDataToWeatherData(apiData, settings.location, true);
|
||||||
if (weatherData) {
|
if (weatherData) {
|
||||||
currentYearData = await storage.createWeatherData(weatherData);
|
try {
|
||||||
|
currentYearData = await storage.createWeatherData(weatherData);
|
||||||
|
console.log("✅ [CACHE] Current year data saved to cache");
|
||||||
|
} catch (error: any) {
|
||||||
|
console.warn("⚠️ [CACHE] Could not save current year data (may already exist):", error.message);
|
||||||
|
// Récupérer les données existantes au lieu de créer
|
||||||
|
currentYearData = await storage.getWeatherData(today, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch previous year data if not in cache
|
// Fetch previous year data if not in cache
|
||||||
if (!previousYearData) {
|
if (!previousYearData) {
|
||||||
console.log("🌤️ Fetching previous year weather data from API");
|
console.log("🌤️ [FETCH] Fetching previous year weather data from API");
|
||||||
const apiData = await weatherService.fetchPreviousYearWeather(settings, previousYearDate);
|
const apiData = await weatherService.fetchPreviousYearWeather(settings, previousYearDate);
|
||||||
if (apiData) {
|
if (apiData) {
|
||||||
const weatherData = weatherService.convertApiDataToWeatherData(apiData, settings.location, false);
|
const weatherData = weatherService.convertApiDataToWeatherData(apiData, settings.location, false);
|
||||||
if (weatherData) {
|
if (weatherData) {
|
||||||
previousYearData = await storage.createWeatherData(weatherData);
|
try {
|
||||||
|
previousYearData = await storage.createWeatherData(weatherData);
|
||||||
|
console.log("✅ [CACHE] Previous year data saved to cache");
|
||||||
|
} catch (error: any) {
|
||||||
|
console.warn("⚠️ [CACHE] Could not save previous year data (may already exist):", error.message);
|
||||||
|
// Récupérer les données existantes au lieu de créer
|
||||||
|
previousYearData = await storage.getWeatherData(previousYearDate, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.warn("⚠️ [HISTORY] Could not fetch historical data - continuing with current year only");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { WeatherData, WeatherSettings } from "../shared/schema.js";
|
import { WeatherData, WeatherSettings, InsertWeatherData } from "../shared/schema.js";
|
||||||
|
|
||||||
export interface WeatherApiResponse {
|
export interface WeatherApiResponse {
|
||||||
days: Array<{
|
days: Array<{
|
||||||
@@ -72,7 +72,7 @@ export class WeatherService {
|
|||||||
/**
|
/**
|
||||||
* Convertit les données de l'API en format WeatherData
|
* Convertit les données de l'API en format WeatherData
|
||||||
*/
|
*/
|
||||||
convertApiDataToWeatherData(apiData: WeatherApiResponse, location: string, isCurrentYear: boolean): WeatherData | null {
|
convertApiDataToWeatherData(apiData: WeatherApiResponse, location: string, isCurrentYear: boolean): InsertWeatherData | null {
|
||||||
if (!apiData.days || apiData.days.length === 0) {
|
if (!apiData.days || apiData.days.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -80,16 +80,15 @@ export class WeatherService {
|
|||||||
const todayData = apiData.days[0];
|
const todayData = apiData.days[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 0, // Sera généré par la base de données
|
// Pas d'ID - sera auto-généré par PostgreSQL serial
|
||||||
date: todayData.datetime,
|
date: todayData.datetime,
|
||||||
location,
|
location,
|
||||||
tempMax: todayData.tempmax.toString(),
|
tempMax: todayData.tempmax.toString(),
|
||||||
tempMin: todayData.tempmin.toString(),
|
tempMin: todayData.tempmin.toString(),
|
||||||
icon: todayData.icon,
|
icon: todayData.icon,
|
||||||
conditions: todayData.conditions,
|
conditions: todayData.conditions,
|
||||||
isCurrentYear,
|
isCurrentYear
|
||||||
createdAt: new Date(),
|
// Pas de createdAt/updatedAt - gérés par la base de données
|
||||||
updatedAt: new Date()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user