Skip to content

Commit

Permalink
Fix >16 JSON algo
Browse files Browse the repository at this point in the history
Signed-off-by: Kartikay <[email protected]>
  • Loading branch information
kartikaysaxena committed Dec 11, 2023
1 parent 81be397 commit 0ed240b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
26 changes: 15 additions & 11 deletions packages/site/src/components/Chart.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
// Chart.js
import * as React from 'react';
import { LineChart } from '@mui/x-charts/LineChart';

Check failure on line 3 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

'@mui/x-charts' should be listed in the project's dependencies. Run 'npm i -S @mui/x-charts' to add it

Check failure on line 3 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

`@mui/x-charts/LineChart` import should occur before import of `react`
import Box from '@mui/material/Box';

Check failure on line 4 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

'@mui/material' should be listed in the project's dependencies. Run 'npm i -S @mui/material' to add it

Check failure on line 4 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

`@mui/material/Box` import should occur before import of `react`

export const Chart = ({ data }) => {

Check failure on line 7 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Replace `⏎····const·xAxisData·=·Object.keys(data).map((key)·=>·parseInt(key.replace('price_',·''))` with `··const·xAxisData·=·Object.keys(data).map((key)·=>⏎····parseInt(key.replace('price_',·'')),⏎··`
const xAxisData = Array.from({ length: 16 }, (_, index) => index + 1);
const xAxisData = Object.keys(data).map((key) => parseInt(key.replace('price_', '')));

Check failure on line 8 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Missing radix parameter

const yAxisData = data.map((entry) => entry.usdValue);

return (
<LineChart
xAxis={[{ data: xAxisData }]}
series={[{ data: yAxisData }]}
width={500}
height={300}
/>
);
const yAxisData = Object.values(data);

Check failure on line 10 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Delete `··`

Check failure on line 11 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Delete `··`
return (

Check failure on line 12 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Delete `··`
<Box sx={{ backgroundColor: 'white', p: 2, borderRadius: 8, borderColor: 'black', border: 2, marginTop: '2 rem' }}>

Check failure on line 13 in packages/site/src/components/Chart.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Replace `····<Box·sx={{·backgroundColor:·'white',·p:·2,·borderRadius:·8,·borderColor:·'black',·border:·2,··marginTop:·'2·rem'·}}>` with `<Box⏎······sx={{⏎········backgroundColor:·'white',⏎········p:·2,⏎········borderRadius:·8,⏎········borderColor:·'black',⏎········border:·2,⏎········marginTop:·'2·rem',⏎······}}`
<p>USD Price Chart of last 16 minutes</p>
<LineChart
xAxis={[{ data: xAxisData }]}
series={[{ data: yAxisData }]}
width={500}
height={300}
/>
</Box>
);
};
28 changes: 14 additions & 14 deletions packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,20 @@ const Index = () => {
return time;
};

function shiftAndReplaceLast(jsonObj, newValue) {
const x = Object.values(jsonObj);
for(var i = 1; i < x.length; i++) {
x[i-1] = x[i];
}

x[x.length-1] = newValue;
console.log(x);
console.log(x[x.length-3]);
const updatedJson = {};
x.forEach((value, index) => {
updatedJson[`price_${index}`] = value;
});
return updatedJson;
function shiftAndReplaceLast(jsonObject, newValue) {

const keys = Object.keys(jsonObject);

// Reverse cyclically shift the values
for (let i = 0; i < keys.length - 1; i++) {
jsonObject[keys[i]] = jsonObject[keys[i + 1]];
}

// Set the new value for the last key
jsonObject[keys[keys.length - 1]] = newValue;


return jsonObject;
}
let counter = 0; // Initialize counter to start from 0
let newJSON ={}
Expand Down

0 comments on commit 0ed240b

Please sign in to comment.