Skip to content

Commit

Permalink
refactor: update financial data for current year (#2687)
Browse files Browse the repository at this point in the history
Co-authored-by: Akshat Nema <76521428+akshatnema@users.noreply.github.com>
  • Loading branch information
JeelRajodiya and akshatnema authored Sep 29, 2024
1 parent 3f6ed81 commit a502c8e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
4 changes: 2 additions & 2 deletions components/FinancialSummary/BarChartComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Bar, BarChart, CartesianGrid, Legend, Tooltip, YAxis } from 'recharts';

import type { ExpenseItem, ExpensesLinkItem } from '@/types/FinancialSummary/BarChartComponent';

import ExpensesData from '../../config/finance/json-data/2024/Expenses.json';
import ExpensesLinkData from '../../config/finance/json-data/2024/ExpensesLink.json';
import ExpensesData from '../../config/finance/json-data/Expenses.json';
import ExpensesLinkData from '../../config/finance/json-data/ExpensesLink.json';
import { getUniqueCategories } from '../../utils/getUniqueCategories';
import CustomTooltip from './CustomTooltip';
import ExpensesCard from './ExpensesCard';
Expand Down
2 changes: 1 addition & 1 deletion components/FinancialSummary/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ExpenseItem, Expenses } from '@/types/FinancialSummary/BarChartComponent';

import ExpensesLinkData from '../../config/finance/json-data/2024/ExpensesLink.json';
import ExpensesLinkData from '../../config/finance/json-data/ExpensesLink.json';

/**
* @description Card component displays expense details for a specific month.
Expand Down
2 changes: 1 addition & 1 deletion components/FinancialSummary/ExpensesCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Expenses } from '@/types/FinancialSummary/BarChartComponent';

import ExpensesData from '../../config/finance/json-data/2024/Expenses.json';
import ExpensesData from '../../config/finance/json-data/Expenses.json';
import Card from './Card';

/**
Expand Down
14 changes: 5 additions & 9 deletions scripts/finance/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
const { promises: { mkdir } } = require('fs');
const {
promises: { mkdir }
} = require('fs');
const { resolve } = require('path');
const writeJSON = require('../utils/readAndWriteJson.js');

module.exports = async function buildFinanceInfoList({
currentDir,
configDir,
financeDir,
year,
jsonDataDir
}) {
module.exports = async function buildFinanceInfoList({ currentDir, configDir, financeDir, year, jsonDataDir }) {
try {
const expensesPath = resolve(currentDir, configDir, financeDir, year, 'Expenses.yml');
const expensesLinkPath = resolve(currentDir, configDir, financeDir, year, 'ExpensesLink.yml');

// Ensure the directory exists before writing the files
const jsonDirectory = resolve(currentDir, configDir, financeDir, jsonDataDir, year);
const jsonDirectory = resolve(currentDir, configDir, financeDir, jsonDataDir);
await mkdir(jsonDirectory, { recursive: true });

// Write Expenses and ExpensesLink to JSON files
Expand Down
27 changes: 24 additions & 3 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { resolve } = require('path');
const fs = require('fs');
const rssFeed = require('./build-rss');
const buildPostList = require('./build-post-list');
const buildCaseStudiesList = require('./casestudies');
const buildAdoptersList = require('./adopters')
const buildAdoptersList = require('./adopters');
const buildFinanceInfoList = require('./finance');
const { resolve } = require('path');

async function start() {
await buildPostList();
Expand All @@ -18,11 +19,31 @@ async function start() {
resolve(__dirname, '../config', 'case-studies.json')
);
await buildAdoptersList();
const financeDir = resolve('.', 'config', 'finance');

// loop through all the files finance in directory and find the latest year to build the finance info list
const yearsList = fs
.readdirSync(financeDir)
// filter out any files that are not numbers
.filter((file) => {
return !Number.isNaN(parseFloat(file));
})
// sort the years in descending order
.sort((a, b) => {
return parseFloat(b) - parseFloat(a);
});

if (yearsList.length === 0) {
throw new Error('No finance data found in the finance directory.');
}

const latestYear = yearsList[0];

await buildFinanceInfoList({
currentDir: '.',
configDir: 'config',
financeDir: 'finance',
year: '2024',
year: latestYear,
jsonDataDir: 'json-data'
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/finance/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');
const buildFinanceInfoList = require('../../scripts/finance/index');
const { expensesYaml, expensesLinkYaml, expensesjson, expensesLinkjson } = require("../fixtures/financeData")
const { expensesYaml, expensesLinkYaml, expensesjson, expensesLinkjson } = require('../fixtures/financeData');

describe('buildFinanceInfoList', () => {
const testDir = path.resolve(__dirname, 'test-finance-info');
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('buildFinanceInfoList', () => {
jsonDataDir
});

const jsonDir = path.resolve(testDir, configDir, financeDir, jsonDataDir, year);
const jsonDir = path.resolve(testDir, configDir, financeDir, jsonDataDir);

// Check if JSON directory was created
expect(fs.existsSync(jsonDir)).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion utils/getUniqueCategories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Expenses from '../config/finance/json-data/2024/Expenses.json';
import Expenses from '../config/finance/json-data/Expenses.json';

/**
* Retrieves unique expense categories from the Expenses data.
Expand Down

0 comments on commit a502c8e

Please sign in to comment.