Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prettier formatting #177

Merged
merged 7 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ POSTGRES_PORT=5432
POSTGRES_USER=postgres_user
POSTGRES_PASSWORD=your_postgres_password
POSTGRES_DB=your_postgres_db
# NEXT_PUBLIC_MAPBOX_TOKEN = mapbox token optional for future globe feature
# NEXT_PUBLIC_MAPBOX_TOKEN = mapbox token optional for future globe feature
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Continuous Integration

on:
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
lint:
timeout-minutes: 10
name: "lint"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm ci

- run: npx prettier --check .
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ next-env.d.ts
# pixi env
pixi_env/

.codegpt
.codegpt
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0 # this is optional, use `pre-commit autoupdate` to get the latest rev!
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 4 additions & 4 deletions app/2050/R3fGlobeScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ const GlobeViz = () => {
const [position, setPosition] = useState<Vector3>(new Vector3(60, 60, 60));
const [globeReady, setGlobeReady] = useState(false);

const endpoints = useMemo(() =>
const endpoints = useMemo(() =>
Object.keys(COUNTRY_COORDINATES).map(
(country) => getGeoJsonData(country).countryView
), []
);

const { data, error } = useSWR(endpoints, async (urls) => {
const responses = await Promise.all(
urls.map((url) =>
urls.map((url) =>
fetch(url)
.then(res => {
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
Expand All @@ -101,7 +101,7 @@ const GlobeViz = () => {
const getPolygonColor = useCallback(
(d: any) => {
if (!d?.id) return "#7C9885";

const countryCode = d.properties?.country_code?.toUpperCase();
if (!countryCode) return "#7C9885";

Expand Down Expand Up @@ -136,7 +136,7 @@ const GlobeViz = () => {
(d: any) => {
const countryCode = d.properties?.country_code?.toUpperCase();
let baseColor = "#7C9885";

if (selectedCountry === countryCode) {
baseColor = "#E41E3C";
} else if (hoveredCountry === countryCode) {
Expand Down
12 changes: 6 additions & 6 deletions app/api/bustotal/[country]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function GET(
const result = await pool.query(
`
WITH stats AS (
SELECT
SELECT
bus,
SUM(p_nom) as total_capacity,
ntile(5) OVER (ORDER BY SUM(p_nom)) as break_group
Expand All @@ -29,14 +29,14 @@ export async function GET(
HAVING SUM(p_nom) > 0
),
break_ranges AS (
SELECT
SELECT
break_group,
MIN(total_capacity) as min_capacity,
MAX(total_capacity) as max_capacity
FROM stats
GROUP BY break_group
)
SELECT
SELECT
s.bus,
s.total_capacity,
s.break_group,
Expand All @@ -56,7 +56,7 @@ export async function GET(
max: row.group_max
})))).sort((a, b) => a.group - b.group);

return NextResponse.json({
return NextResponse.json({
data: result.rows,
meta: {
count: result.rows.length,
Expand All @@ -65,8 +65,8 @@ export async function GET(
}
});
} catch (error) {
return NextResponse.json({
return NextResponse.json({
error: "Error fetching data"
}, { status: 500 });
}
}
}
2 changes: 1 addition & 1 deletion app/api/capacity_comparison/[country]/[horizon]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export async function GET(
console.error("Error fetching data from PostgreSQL:", error);
return NextResponse.json({ error: "Error fetching data" }, { status: 500 });
}
}
}
2 changes: 1 addition & 1 deletion app/api/capacity_comparison/[country]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export async function GET(
} catch (error) {
return NextResponse.json({ error: "Error fetching data" }, { status: 500 });
}
}
}
2 changes: 1 addition & 1 deletion app/api/capacity_expansion/[country]/[horizon]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export async function GET(
{ status: 500 }
);
}
}
}
2 changes: 1 addition & 1 deletion app/api/co2_emissions/[country]/[horizon]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export async function GET(
{ status: 500 }
);
}
}
}
2 changes: 1 addition & 1 deletion app/api/demand_comparison/[country]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export async function GET(
} catch (error) {
return NextResponse.json({ error: "Error fetching data" }, { status: 500 });
}
}
}
2 changes: 1 addition & 1 deletion app/api/electricity_prices/[country]/[horizon]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export async function GET(
{ status: 500 }
);
}
}
}
2 changes: 1 addition & 1 deletion app/api/generation_comparison/[country]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export async function GET(
} catch (error) {
return NextResponse.json({ error: "Error fetching data" }, { status: 500 });
}
}
}
2 changes: 1 addition & 1 deletion app/api/generation_mix/[country]/[horizon]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export async function GET(
{ status: 500 }
);
}
}
}
2 changes: 1 addition & 1 deletion app/api/generation_mix/[country]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ export async function GET(
console.error("Error fetching data from PostgreSQL:", error);
return NextResponse.json({ error: "Error fetching data" }, { status: 500 });
}
}
}
20 changes: 10 additions & 10 deletions app/api/geography/buses/[country]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ export async function GET(
try {
const { country } = params;
const url = new URL(request.url);

const page = parseInt(url.searchParams.get('page') || '1');
const pageSize = parseInt(url.searchParams.get('pageSize') || String(DEFAULT_PAGE_SIZE));
const offset = (page - 1) * pageSize;

const simplification = parseFloat(url.searchParams.get('simplification') || String(GEOMETRY_SIMPLIFICATION));

if (!validateCountry(country)) {
return createErrorResponse('Invalid country code', 400);
}

return await withDbClient(async (client) => {
const materializedViewName = `buses_${country}_materialized`;

const viewCheck = await client.query(`
SELECT EXISTS (
SELECT FROM pg_matviews
WHERE schemaname = 'public'
SELECT FROM pg_matviews
WHERE schemaname = 'public'
AND matviewname = $1
);
`, [materializedViewName]);

const tableName = viewCheck.rows[0].exists ? materializedViewName : `buses_${country}`;

const countQuery = `
SELECT COUNT(*)
SELECT COUNT(*)
FROM ${tableName}
WHERE geometry IS NOT NULL;
`;
Expand All @@ -48,7 +48,7 @@ export async function GET(

const query = `
WITH base_data AS (
SELECT
SELECT
"Bus",
v_nom,
country,
Expand Down Expand Up @@ -91,16 +91,16 @@ export async function GET(
FROM base_data
) features;
`;

const result = await client.query(query, [simplification, pageSize, offset]);

const headers = new Headers();
headers.set('Cache-Control', 'public, s-maxage=3600');

return formatGeoJsonResponse(result, headers);
});
} catch (error) {
console.error('Buses API Error:', error);
return createErrorResponse('Internal Server Error', 500);
}
}
}
4 changes: 2 additions & 2 deletions app/api/geography/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function validateCountry(country: string): boolean {

// Optimized GeoJSON response formatter
export function formatGeoJsonResponse(result: any, headers?: Headers) {
const response = (result.features)
const response = (result.features)
? NextResponse.json(result)
: result.rows?.[0]?.jsonb_build_object
? NextResponse.json(result.rows[0].jsonb_build_object)
Expand Down Expand Up @@ -215,4 +215,4 @@ export async function withDbClient<T>(callback: (client: any) => Promise<T>): Pr
} finally {
client.release();
}
}
}
20 changes: 10 additions & 10 deletions app/api/geography/countryView/[country]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ export async function GET(
try {
const { country } = params;
const url = new URL(request.url);

const page = parseInt(url.searchParams.get('page') || '1');
const pageSize = parseInt(url.searchParams.get('pageSize') || String(DEFAULT_PAGE_SIZE));
const offset = (page - 1) * pageSize;

const simplification = parseFloat(url.searchParams.get('simplification') || String(GEOMETRY_SIMPLIFICATION));

if (!validateCountry(country)) {
return createErrorResponse('Invalid country code', 400);
}

return await withDbClient(async (client) => {
const materializedViewName = `${country}_country_view_materialized`;

const viewCheck = await client.query(`
SELECT EXISTS (
SELECT FROM pg_matviews
WHERE schemaname = 'public'
SELECT FROM pg_matviews
WHERE schemaname = 'public'
AND matviewname = $1
);
`, [materializedViewName]);

const tableName = viewCheck.rows[0].exists ? materializedViewName : `${country}_country_view`;

const countQuery = `
SELECT COUNT(*)
SELECT COUNT(*)
FROM ${tableName}
WHERE geometry IS NOT NULL;
`;
Expand All @@ -48,7 +48,7 @@ export async function GET(

const query = `
WITH base_data AS (
SELECT
SELECT
country_name,
ST_SimplifyPreserveTopology(geometry, $1) as geometry
FROM ${tableName}
Expand Down Expand Up @@ -80,16 +80,16 @@ export async function GET(
FROM base_data
) features;
`;

const result = await client.query(query, [simplification, pageSize, offset]);

const headers = new Headers();
headers.set('Cache-Control', 'public, s-maxage=3600');

return formatGeoJsonResponse(result, headers);
});
} catch (error) {
console.error('CountryView API Error:', error);
return createErrorResponse('Internal Server Error', 500);
}
}
}
Loading
Loading