feature/syasya/testlayout #7
@ -162,6 +162,7 @@ const AdminDashboard = () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  doc.save('dashboard_charts.pdf');
 | 
					  doc.save('dashboard_charts.pdf');
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					  const currentMonth = new Date().toISOString().slice(0, 7); // "YYYY-MM"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <DashboardLayout>
 | 
					    <DashboardLayout>
 | 
				
			||||||
@ -184,7 +185,7 @@ const AdminDashboard = () => {
 | 
				
			|||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <div>
 | 
					          <div>
 | 
				
			||||||
            <KPI_Table siteId={siteIdMap[selectedSite]} month="2025-07" />
 | 
					          <KPI_Table siteId={siteIdMap[selectedSite]} month={currentMonth} />
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -127,9 +127,10 @@ const EnergyLineChart = ({ siteId }: EnergyLineChartProps) => {
 | 
				
			|||||||
  const groupedGeneration = groupTimeSeries(generation, viewMode);
 | 
					  const groupedGeneration = groupTimeSeries(generation, viewMode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const allTimes = Array.from(new Set([
 | 
					  const allTimes = Array.from(new Set([
 | 
				
			||||||
    ...groupedConsumption.map(d => d.time),
 | 
					  ...groupedConsumption.map(d => d.time),
 | 
				
			||||||
    ...groupedGeneration.map(d => d.time),
 | 
					  ...groupedGeneration.map(d => d.time),
 | 
				
			||||||
  ])).sort();
 | 
					])).sort((a, b) => new Date(a).getTime() - new Date(b).getTime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const consumptionMap = Object.fromEntries(groupedConsumption.map(d => [d.time, d.value]));
 | 
					  const consumptionMap = Object.fromEntries(groupedConsumption.map(d => [d.time, d.value]));
 | 
				
			||||||
  const generationMap = Object.fromEntries(groupedGeneration.map(d => [d.time, d.value]));
 | 
					  const generationMap = Object.fromEntries(groupedGeneration.map(d => [d.time, d.value]));
 | 
				
			||||||
 | 
				
			|||||||
@ -12,8 +12,12 @@ interface MonthlyKPI {
 | 
				
			|||||||
  consumption_kwh: number | null;
 | 
					  consumption_kwh: number | null;
 | 
				
			||||||
  grid_draw_kwh: number | null;
 | 
					  grid_draw_kwh: number | null;
 | 
				
			||||||
  efficiency: number | null;
 | 
					  efficiency: number | null;
 | 
				
			||||||
 | 
					  peak_demand_kw: number | null; // ✅ new
 | 
				
			||||||
 | 
					  avg_power_factor: number | null; // ✅ new
 | 
				
			||||||
 | 
					  load_factor: number | null;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const KPI_Table: React.FC<KPI_TableProps> = ({ siteId, month }) => {
 | 
					const KPI_Table: React.FC<KPI_TableProps> = ({ siteId, month }) => {
 | 
				
			||||||
  const [kpiData, setKpiData] = useState<MonthlyKPI | null>(null);
 | 
					  const [kpiData, setKpiData] = useState<MonthlyKPI | null>(null);
 | 
				
			||||||
  const [loading, setLoading] = useState(false);
 | 
					  const [loading, setLoading] = useState(false);
 | 
				
			||||||
@ -63,13 +67,20 @@ const KPI_Table: React.FC<KPI_TableProps> = ({ siteId, month }) => {
 | 
				
			|||||||
  const consumption_kwh = kpiData?.consumption_kwh ?? 0;
 | 
					  const consumption_kwh = kpiData?.consumption_kwh ?? 0;
 | 
				
			||||||
  const grid_draw_kwh = kpiData?.grid_draw_kwh ?? 0;
 | 
					  const grid_draw_kwh = kpiData?.grid_draw_kwh ?? 0;
 | 
				
			||||||
  const efficiency = kpiData?.efficiency ?? 0;
 | 
					  const efficiency = kpiData?.efficiency ?? 0;
 | 
				
			||||||
 | 
					  const peak_demand_kw = kpiData?.peak_demand_kw ?? 0;
 | 
				
			||||||
 | 
					  const power_factor = kpiData?.avg_power_factor ?? 0;
 | 
				
			||||||
 | 
					  const load_factor = kpiData?.load_factor ?? 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const data = [
 | 
				
			||||||
 | 
					  { kpi: 'Monthly Yield', value: `${yield_kwh.toFixed(0)} kWh` },
 | 
				
			||||||
 | 
					  { kpi: 'Monthly Consumption', value: `${consumption_kwh.toFixed(0)} kWh` },
 | 
				
			||||||
 | 
					  { kpi: 'Monthly Grid Draw', value: `${grid_draw_kwh.toFixed(0)} kWh` },
 | 
				
			||||||
 | 
					  { kpi: 'Efficiency', value: `${efficiency.toFixed(1)}%` },
 | 
				
			||||||
 | 
					  { kpi: 'Peak Demand', value: `${peak_demand_kw.toFixed(2)} kW` }, // ✅ added
 | 
				
			||||||
 | 
					  { kpi: 'Power Factor', value: `${power_factor.toFixed(2)} kW` }, // ✅ added
 | 
				
			||||||
 | 
					  { kpi: 'Load Factor', value: `${load_factor.toFixed(2)} kW` }, // ✅ added
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const data = [
 | 
					 | 
				
			||||||
    { kpi: 'Monthly Yield', value: `${yield_kwh.toFixed(0)} kWh` },
 | 
					 | 
				
			||||||
    { kpi: 'Monthly Consumption', value: `${consumption_kwh.toFixed(0)} kWh` },
 | 
					 | 
				
			||||||
    { kpi: 'Monthly Grid Draw', value: `${grid_draw_kwh.toFixed(0)} kWh` },
 | 
					 | 
				
			||||||
    { kpi: 'Efficiency', value: `${efficiency.toFixed(1)}%` },
 | 
					 | 
				
			||||||
  ];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
@ -84,8 +95,8 @@ const KPI_Table: React.FC<KPI_TableProps> = ({ siteId, month }) => {
 | 
				
			|||||||
        <tbody>
 | 
					        <tbody>
 | 
				
			||||||
          {data.map((row) => (
 | 
					          {data.map((row) => (
 | 
				
			||||||
            <tr key={row.kpi}>
 | 
					            <tr key={row.kpi}>
 | 
				
			||||||
              <td className="border border-gray-700 p-3">{row.kpi}</td>
 | 
					              <td className="border border-gray-700 p-2.5">{row.kpi}</td>
 | 
				
			||||||
              <td className="border border-gray-700 p-3">{row.value}</td>
 | 
					              <td className="border border-gray-700 p-2.5">{row.value}</td>
 | 
				
			||||||
            </tr>
 | 
					            </tr>
 | 
				
			||||||
          ))}
 | 
					          ))}
 | 
				
			||||||
        </tbody>
 | 
					        </tbody>
 | 
				
			||||||
 | 
				
			|||||||
@ -124,7 +124,10 @@ const MonthlyBarChart: React.FC<MonthlyBarChartProps> = ({ siteId }) => {
 | 
				
			|||||||
          <BarChart data={chartData}>
 | 
					          <BarChart data={chartData}>
 | 
				
			||||||
            <XAxis dataKey="month" tick={{ fontSize: 10 }} />
 | 
					            <XAxis dataKey="month" tick={{ fontSize: 10 }} />
 | 
				
			||||||
            <YAxis tick={{ fontSize: 10 }} />
 | 
					            <YAxis tick={{ fontSize: 10 }} />
 | 
				
			||||||
            <Tooltip />
 | 
					            <Tooltip
 | 
				
			||||||
 | 
					              formatter={(value: number) => [`${value.toFixed(2)} kWh`]}
 | 
				
			||||||
 | 
					              labelFormatter={(label) => `${label}`}
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
            <Legend />
 | 
					            <Legend />
 | 
				
			||||||
            <Bar dataKey="consumption" fill={consumptionColor} name="Consumption (kWh)" />
 | 
					            <Bar dataKey="consumption" fill={consumptionColor} name="Consumption (kWh)" />
 | 
				
			||||||
            <Bar dataKey="generation" fill={generationColor} name="Generation (kWh)" />
 | 
					            <Bar dataKey="generation" fill={generationColor} name="Generation (kWh)" />
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user