@@ -62,6 +62,8 @@ export default function FishAnalysis() {
62
62
63
63
// Group data by city
64
64
data . forEach ( item => {
65
+ if ( ! item . location ?. details ?. city || ! item . location ?. details ?. district ) return ;
66
+
65
67
const cityKey = `${ item . location . details . city } - ${ item . location . details . district } ` ;
66
68
if ( ! stats [ cityKey ] ) {
67
69
stats [ cityKey ] = {
@@ -77,11 +79,15 @@ export default function FishAnalysis() {
77
79
} ;
78
80
}
79
81
80
- const timeKey = item . timestamp . time . split ( ':' ) [ 0 ] ;
82
+ const timeKey = item . timestamp ? .time ? .split ( ':' ) [ 0 ] || '0' ;
81
83
stats [ cityKey ] . popularTimes [ timeKey ] = ( stats [ cityKey ] . popularTimes [ timeKey ] || 0 ) + 1 ;
82
84
stats [ cityKey ] . totalCatches ++ ;
83
- stats [ cityKey ] . averageTemp = ( stats [ cityKey ] . averageTemp * ( stats [ cityKey ] . totalCatches - 1 ) +
84
- item . weather . temperature ) / stats [ cityKey ] . totalCatches ;
85
+
86
+ // Only include temperature if it exists
87
+ if ( item . weather ?. temperature ) {
88
+ const currentTotal = stats [ cityKey ] . averageTemp * ( stats [ cityKey ] . totalCatches - 1 ) ;
89
+ stats [ cityKey ] . averageTemp = ( currentTotal + item . weather . temperature ) / stats [ cityKey ] . totalCatches ;
90
+ }
85
91
86
92
const uniqueUsers = new Set ( [ ...Array . from ( new Set ( [ item . userId ] ) ) ] ) ;
87
93
stats [ cityKey ] . totalUsers = uniqueUsers . size ;
@@ -130,8 +136,18 @@ export default function FishAnalysis() {
130
136
131
137
querySnapshot . forEach ( ( doc ) => {
132
138
const docData = doc . data ( ) ;
133
- if ( docData . location && docData . location . coordinates ) {
134
- data . push ( docData as FishingData ) ;
139
+ // Only include entries that have valid location data
140
+ if ( docData . location ?. coordinates ?. latitude && docData . location ?. coordinates ?. longitude ) {
141
+ // Ensure weather object exists even if empty
142
+ const fishingData : FishingData = {
143
+ ...docData ,
144
+ weather : docData . weather || {
145
+ temperature : 0 ,
146
+ windSpeed : 0 ,
147
+ windDirection : 0
148
+ }
149
+ } as FishingData ;
150
+ data . push ( fishingData ) ;
135
151
}
136
152
} ) ;
137
153
0 commit comments