Skip to content

Commit

Permalink
feat: remove query based politician funfact section
Browse files Browse the repository at this point in the history
  • Loading branch information
Th1nkK1D committed Nov 21, 2024
1 parent 0ccc172 commit 2fd5128
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 97 deletions.
21 changes: 3 additions & 18 deletions src/components/Index/PoliticianContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}
export let highlightedPoliticians: HighlightedPolitician[];
export let otherSourcesHighlightedPoliticians: HighlightedPolitician[];
async function getExternalHighlightedPoliticians(): Promise<HighlightedPolitician[]> {
const { politicianWithMostWikipediaVisit, politicianWithMostGun, updatedAt } =
Expand All @@ -30,30 +29,16 @@
}
</script>

<div>
<h3 class="fluid-heading-04">นักการเมืองชุดล่าสุดที่น่าสนใจ</h3>
<p class="label-01 mb-6 text-gray-60">
หมายเหตุ : ในกรณีที่มีมากกว่า 1 คน จะเลือกจากลำดับตัวอักษรในชื่อ
</p>
<div class="grid grid-cols-1 gap-3 md:grid-cols-3">
{#each highlightedPoliticians as politicianData (politicianData.reason)}
<StatCard {politicianData} />
{/each}
</div>
</div>
<div>
<h3 class="heading-01 relative mb-6 text-center">
<span class="absolute left-0 top-1/2 h-[1px] w-full bg-text-03" aria-hidden="true" />
<span class="relative z-10 bg-ui-01 px-2 text-text-03">คัดเลือกโดยใช้แหล่งข้อมูลอื่นๆ</span>
</h3>
<div class="space-y-6">
<h3 class="fluid-heading-04">นักการเมืองที่น่าสนใจ</h3>
{#await getExternalHighlightedPoliticians()}
<InlineLoading class="flex items-center justify-center p-12" />
{:then externalHighlightedPoliticians}
<Carousel
arrowLeftClass="top-auto bottom-[75px] translate-y-1/2"
arrowRightClass="top-auto bottom-[75px] translate-y-1/2"
>
{#each [...otherSourcesHighlightedPoliticians, ...externalHighlightedPoliticians] as politicianData (politicianData.reason)}
{#each [...highlightedPoliticians, ...externalHighlightedPoliticians] as politicianData (politicianData.reason)}
<StatCard class="keen-slider__slide" {politicianData} />
{/each}
</Carousel>
Expand Down
72 changes: 1 addition & 71 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import { safeFind } from '$lib/datasheets/processor.js';
import { getHighlightedVoteByGroups } from '$lib/datasheets/voting.js';
import { BillStatus } from '$models/bill';
import { PromiseStatus } from '$models/promise';
import { DefaultVoteOption } from '$models/voting.js';
import type { PromisesByStatus } from './promises/+page.server';
import { groups, rollup } from 'd3-array';
import dayjs from 'dayjs';
import type { ComponentProps } from 'svelte';

const MAX_LATEST_VOTE = 5;
Expand All @@ -47,83 +45,16 @@ interface MostFrequentlyServedAsMinisterPolitician extends HighlightedPolitician
export async function load() {
const politicians = await fetchPoliticians();
const votes = await fetchVotes();
const votings = await fetchVotings();
const bills = await fetchBills();
const promises = await fetchPromises();
const assembles = await fetchAssemblies();

const activePoliticians = politicians.filter(({ isActive }) => isActive);

const votesInActiveAssemblies = votes.filter(({ votingId }) =>
votings
.find(({ id }) => id === votingId)
?.participatedAssemblies.some(({ endedAt }) => !endedAt)
);

const highlightedPoliticians: HighlightedPolitician[] = [
// TODO: Not release assets and debts yet
// {
// reason: HighlightedReason.HighestAssetOwned,
// value: 95787230000,
// politician: movingForwardPolitician
// },
// {
// reason: HighlightedReason.HighestDebtOwned,
// value: 1862770000,
// politician: movingForwardPolitician
// },
{
reason: HighlightedReason.HighestPartySwitching,
...activePoliticians
.map((politician) => ({
politician,
value: new Set(politician.partyRoles.map(({ party }) => party.name)).size
}))
.sort((a, z) => z.value - a.value)[0]
},
{
reason: HighlightedReason.HighestAbsentRate,
...activePoliticians
.map((politician) => {
const theirVotes = votesInActiveAssemblies.filter(
({ politicianId }) => politicianId === politician.id
);

return {
politician,
value:
theirVotes.length > 0
? theirVotes.filter(({ voteOption }) => voteOption === DefaultVoteOption.Absent)
.length / theirVotes.length
: 0
};
})
.sort((a, z) => z.value - a.value)[0]
},
{
reason: HighlightedReason.HighestBillProposed,
...activePoliticians
.map((politician) => ({
politician,
value: bills.filter((bill) => bill.proposedLedByPolitician?.id === politician.id).length
}))
.sort((a, z) => z.value - a.value)[0]
},
{
reason: HighlightedReason.Youngest,
...activePoliticians
.map((politician) => ({
politician,
value: politician.birthdate ? dayjs().diff(politician.birthdate, 'years') : 999
}))
.sort((a, z) => a.value - z.value)[0]
}
];

const chuanLeekpai = safeFind(activePoliticians, (p) => p.id === 'ชวน-หลีกภัย');
const banyatBantadtan = safeFind(activePoliticians, (p) => p.id === 'บัญญัติ-บรรทัดฐาน');

const otherSourcesHighlightedPoliticians: HighlightedPolitician[] = [
const highlightedPoliticians: HighlightedPolitician[] = [
{
reason: HighlightedReason.LongestServedInPoliticalPositions,
value: 54,
Expand Down Expand Up @@ -213,7 +144,6 @@ export async function load() {

return {
highlightedPoliticians,
otherSourcesHighlightedPoliticians,
latestVotings,
billByCategoryAndStatus,
promiseSummary
Expand Down
10 changes: 2 additions & 8 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
export let data;
$: ({
highlightedPoliticians,
otherSourcesHighlightedPoliticians,
latestVotings,
billByCategoryAndStatus,
promiseSummary
} = data);
$: ({ highlightedPoliticians, latestVotings, billByCategoryAndStatus, promiseSummary } = data);
</script>

<div class="flex flex-col md:h-[calc(100lvh-48px)]">
Expand Down Expand Up @@ -91,7 +85,7 @@
>รู้หน้า รู้ชื่อ แต่ไม่รู้จัก ลองค้นหาประวัติผู้แทนในสภาของเรากันดู มีตั้งแต่ข้อมูลพื้นฐาน
ข้อมูลทรัพย์สิน-หนี้สิน ประวัติทางการเมือง ไปจนถึงผลงานในสภา</span
>
<PoliticianContent {highlightedPoliticians} {otherSourcesHighlightedPoliticians} />
<PoliticianContent {highlightedPoliticians} />
</ContentSection>

<ContentSection
Expand Down

0 comments on commit 2fd5128

Please sign in to comment.