add year sum
This commit is contained in:
@@ -40,13 +40,29 @@ const YearRainfall: FC<YearRainfallProps> = ({loadedAt}) => {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{Object.entries(data)
|
{Object.entries(data)
|
||||||
.map(([month, months]) => {
|
.map(([month, months]) => <tr key={month}>
|
||||||
return <tr key={month}>
|
|
||||||
<td>{months[0].label}</td>
|
<td>{months[0].label}</td>
|
||||||
<td>{months.find(m => m.year === (new Date).getFullYear() && m.month === Number(month))?.values}</td>
|
<td>{months.find(m => m.year === (new Date).getFullYear() && m.month === Number(month))?.values}</td>
|
||||||
<td>{months.find(m => m.year === ((new Date).getFullYear() - 1) && m.month === Number(month))?.values}</td>
|
<td>{months.find(m => m.year === ((new Date).getFullYear() - 1) && m.month === Number(month))?.values}</td>
|
||||||
</tr>
|
</tr>
|
||||||
})}
|
)}
|
||||||
|
<tr className="font-semibold">
|
||||||
|
<td>Total</td>
|
||||||
|
{Object.entries(data).at(0).at(1).map(i => i.year)
|
||||||
|
.sort((a,b) => b > a)
|
||||||
|
.map(year => <td key={year}>
|
||||||
|
{Object.entries(data).reduce((acc, item) => {
|
||||||
|
console.log(item.at(1), year)
|
||||||
|
item.at(1).forEach(month => {
|
||||||
|
console.log(month)
|
||||||
|
if(month.year === year) {
|
||||||
|
acc += month.values
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return acc
|
||||||
|
}, 0)}
|
||||||
|
</td>)}
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
Reference in New Issue
Block a user