Skip to content

Commit 095db8d

Browse files
Copilotpatrickrb
andauthored
Fix propagation data type conversion from PostgreSQL database (#107)
* Initial plan * Fix propagation data type conversion from database Co-authored-by: patrickrb <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: patrickrb <[email protected]> Co-authored-by: Patrick Burns <[email protected]>
1 parent 442b5eb commit 095db8d

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/app/propagation/page.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,29 @@ export default function PropagationPage() {
156156
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
157157
<div className="text-center">
158158
<div className="text-2xl font-bold text-blue-600">
159-
{data.solar_activity.solar_flux_index.toFixed(1)}
159+
{(typeof data.solar_activity.solar_flux_index === 'number'
160+
? data.solar_activity.solar_flux_index
161+
: parseFloat(data.solar_activity.solar_flux_index)).toFixed(1)}
160162
</div>
161163
<div className="text-sm text-muted-foreground">
162164
Solar Flux Index (SFI)
163165
</div>
164166
</div>
165167
<div className="text-center">
166168
<div className="text-2xl font-bold text-orange-600">
167-
{data.solar_activity.a_index.toFixed(1)}
169+
{(typeof data.solar_activity.a_index === 'number'
170+
? data.solar_activity.a_index
171+
: parseFloat(data.solar_activity.a_index)).toFixed(1)}
168172
</div>
169173
<div className="text-sm text-muted-foreground">
170174
A-Index (Daily)
171175
</div>
172176
</div>
173177
<div className="text-center">
174178
<div className="text-2xl font-bold text-purple-600">
175-
{data.solar_activity.k_index.toFixed(1)}
179+
{(typeof data.solar_activity.k_index === 'number'
180+
? data.solar_activity.k_index
181+
: parseFloat(data.solar_activity.k_index)).toFixed(1)}
176182
</div>
177183
<div className="text-sm text-muted-foreground">
178184
K-Index (3-hour)

src/models/Propagation.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import { query } from '@/lib/db';
22
import { SolarActivity, PropagationForecast, BandCondition, PropagationAlert } from '@/types/propagation';
33

4+
// Database row types for DECIMAL fields that come back as strings
5+
interface SolarActivityRow {
6+
id?: number;
7+
timestamp: Date;
8+
solar_flux_index: string; // DECIMAL comes back as string
9+
a_index: string; // DECIMAL comes back as string
10+
k_index: string; // DECIMAL comes back as string
11+
solar_wind_speed?: string | null; // DECIMAL comes back as string
12+
solar_wind_density?: string | null; // DECIMAL comes back as string
13+
xray_class?: string;
14+
created_at?: Date;
15+
updated_at?: Date;
16+
}
17+
418
export class Propagation {
519
/**
620
* Save solar activity data
@@ -33,7 +47,16 @@ export class Propagation {
3347
data.xray_class || null
3448
]);
3549

36-
return result.rows[0];
50+
const row = result.rows[0] as SolarActivityRow;
51+
// Convert DECIMAL fields from strings to numbers
52+
return {
53+
...row,
54+
solar_flux_index: parseFloat(row.solar_flux_index),
55+
a_index: parseFloat(row.a_index),
56+
k_index: parseFloat(row.k_index),
57+
solar_wind_speed: row.solar_wind_speed ? parseFloat(row.solar_wind_speed) : undefined,
58+
solar_wind_density: row.solar_wind_density ? parseFloat(row.solar_wind_density) : undefined
59+
};
3760
}
3861

3962
/**
@@ -49,7 +72,16 @@ export class Propagation {
4972

5073
const result = await query(sql);
5174
if (result.rows[0]) {
52-
return result.rows[0];
75+
const row = result.rows[0] as SolarActivityRow;
76+
// Convert DECIMAL fields from strings to numbers
77+
return {
78+
...row,
79+
solar_flux_index: parseFloat(row.solar_flux_index),
80+
a_index: parseFloat(row.a_index),
81+
k_index: parseFloat(row.k_index),
82+
solar_wind_speed: row.solar_wind_speed ? parseFloat(row.solar_wind_speed) : undefined,
83+
solar_wind_density: row.solar_wind_density ? parseFloat(row.solar_wind_density) : undefined
84+
};
5385
}
5486
} catch (error) {
5587
console.warn('Database unavailable for solar activity query, using fallback:', error);
@@ -109,7 +141,15 @@ export class Propagation {
109141
`;
110142

111143
const result = await query(sql, [startDate, endDate]);
112-
return result.rows;
144+
// Convert DECIMAL fields from strings to numbers for all rows
145+
return result.rows.map((row: SolarActivityRow): SolarActivity => ({
146+
...row,
147+
solar_flux_index: parseFloat(row.solar_flux_index),
148+
a_index: parseFloat(row.a_index),
149+
k_index: parseFloat(row.k_index),
150+
solar_wind_speed: row.solar_wind_speed ? parseFloat(row.solar_wind_speed) : undefined,
151+
solar_wind_density: row.solar_wind_density ? parseFloat(row.solar_wind_density) : undefined
152+
}));
113153
}
114154

115155
/**

0 commit comments

Comments
 (0)