add filters to statistics
This commit is contained in:
@@ -2,6 +2,7 @@ import { BaseApiClient } from './base';
|
|||||||
import { API_CONFIG } from '../config/api';
|
import { API_CONFIG } from '../config/api';
|
||||||
import type { CandidateAssets, CandidateDetails, CandidateExpenses, CandidateIncome, CandidateRedesSociais, CandidateSearchResult, CpfRevealResult, OpenCandDataAvailabilityStats, OpenCandDatabaseStats, PlatformStats, RandomCandidate } from './apiModels';
|
import type { CandidateAssets, CandidateDetails, CandidateExpenses, CandidateIncome, CandidateRedesSociais, CandidateSearchResult, CpfRevealResult, OpenCandDataAvailabilityStats, OpenCandDatabaseStats, PlatformStats, RandomCandidate } from './apiModels';
|
||||||
import type { EnrichmentResponse, StatisticsConfig, ValueSumRequest, ValueSumResponse } from './apiStatisticsModels';
|
import type { EnrichmentResponse, StatisticsConfig, ValueSumRequest, ValueSumResponse } from './apiStatisticsModels';
|
||||||
|
import type { StatisticsRequestFilters, StatisticsRequestOptions } from '../components/StatisticsPage/statisticsRequests';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenCand API client for interacting with the OpenCand platform
|
* OpenCand API client for interacting with the OpenCand platform
|
||||||
@@ -101,8 +102,28 @@ export class OpenCandApi extends BaseApiClient {
|
|||||||
/**
|
/**
|
||||||
* Get the enrichment statistics for candidates
|
* Get the enrichment statistics for candidates
|
||||||
*/
|
*/
|
||||||
async getStatisticsEnrichment(): Promise<EnrichmentResponse[]> {
|
async getStatisticsEnrichment(filters?: StatisticsRequestFilters): Promise<EnrichmentResponse[]> {
|
||||||
return this.get<EnrichmentResponse[]>(`/v1/estatistica/enriquecimento`, { timeout: 90000 });
|
let url = `/v1/estatistica/enriquecimento`;
|
||||||
|
if (filters) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (filters.partido !== null && filters.partido !== undefined) {
|
||||||
|
params.append('partido', filters.partido);
|
||||||
|
}
|
||||||
|
if (filters.uf !== null && filters.uf !== undefined) {
|
||||||
|
params.append('uf', filters.uf);
|
||||||
|
}
|
||||||
|
if (filters.ano !== null && filters.ano !== undefined) {
|
||||||
|
params.append('ano', String(filters.ano));
|
||||||
|
}
|
||||||
|
if (filters.cargo !== null && filters.cargo !== undefined) {
|
||||||
|
params.append('cargo', filters.cargo);
|
||||||
|
}
|
||||||
|
const queryString = params.toString();
|
||||||
|
if (queryString) {
|
||||||
|
url += `?${queryString}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.get<EnrichmentResponse[]>(url, { timeout: 90000 });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -79,7 +79,7 @@ const StatisticsFilters: React.FC<StatisticsFiltersProps> = ({
|
|||||||
{/* Party Filter */}
|
{/* Party Filter */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
||||||
Partido (Opcional)
|
Partido
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
value={localFilters.partido || ''}
|
value={localFilters.partido || ''}
|
||||||
@@ -99,7 +99,7 @@ const StatisticsFilters: React.FC<StatisticsFiltersProps> = ({
|
|||||||
{/* UF Filter */}
|
{/* UF Filter */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
||||||
UF (Opcional)
|
UF
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
value={localFilters.uf || ''}
|
value={localFilters.uf || ''}
|
||||||
@@ -119,7 +119,7 @@ const StatisticsFilters: React.FC<StatisticsFiltersProps> = ({
|
|||||||
{/* Year Filter */}
|
{/* Year Filter */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
||||||
Ano (Opcional)
|
Ano
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
value={localFilters.ano || ''}
|
value={localFilters.ano || ''}
|
||||||
@@ -139,7 +139,7 @@ const StatisticsFilters: React.FC<StatisticsFiltersProps> = ({
|
|||||||
{/* Cargo Filter */}
|
{/* Cargo Filter */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
<label className="block text-sm font-semibold text-gray-600 uppercase tracking-wide">
|
||||||
Cargo (Opcional)
|
Cargo
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
value={localFilters.cargo || ''}
|
value={localFilters.cargo || ''}
|
||||||
|
@@ -24,12 +24,14 @@ export interface StatisticsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface StatisticsRequestOptions {
|
export interface StatisticsRequestOptions {
|
||||||
filters?: {
|
filters?: StatisticsRequestFilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StatisticsRequestFilters {
|
||||||
partido?: string | null;
|
partido?: string | null;
|
||||||
uf?: string | null;
|
uf?: string | null;
|
||||||
ano?: number | null;
|
ano?: number | null;
|
||||||
cargo?: CargoFilter;
|
cargo?: CargoFilter;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// First Row Requests
|
// First Row Requests
|
||||||
@@ -44,9 +46,9 @@ export async function getCandidatesWithMostAssets(options?: StatisticsRequestOpt
|
|||||||
return Array.isArray(response) ? response : [response];
|
return Array.isArray(response) ? response : [response];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEnrichmentData(): Promise<EnrichmentResponse[] | null> {
|
export async function getEnrichmentData(filters?: StatisticsRequestFilters): Promise<EnrichmentResponse[] | null> {
|
||||||
try {
|
try {
|
||||||
return await openCandApi.getStatisticsEnrichment();
|
return await openCandApi.getStatisticsEnrichment(filters);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching enrichment data:', error);
|
console.error('Error fetching enrichment data:', error);
|
||||||
return null;
|
return null;
|
||||||
@@ -167,7 +169,7 @@ export async function fetchAllStatisticsData(options?: StatisticsRequestOptions)
|
|||||||
statesWithMostRevenue
|
statesWithMostRevenue
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
getCandidatesWithMostAssets(options),
|
getCandidatesWithMostAssets(options),
|
||||||
getEnrichmentData(),
|
getEnrichmentData(options?.filters),
|
||||||
getCandidatesWithMostRevenue(options),
|
getCandidatesWithMostRevenue(options),
|
||||||
getCandidatesWithMostExpenses(options),
|
getCandidatesWithMostExpenses(options),
|
||||||
getPartiesWithMostAssets(options),
|
getPartiesWithMostAssets(options),
|
||||||
|
Reference in New Issue
Block a user