Skip to content

Commit 0d3387c

Browse files
committed
Adding the status
1 parent bfb1ce2 commit 0d3387c

File tree

17 files changed

+195
-12
lines changed

17 files changed

+195
-12
lines changed

Client/src/App.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import StockToken from './pages/stockToken';
2424
import ValidateEmail from './pages/ValidateEmail';
2525
import Stats from './pages/Stats';
2626
import MetaTags from './components/MetaTags';
27+
import Status from './pages/Status';
2728

2829

2930
const App: Component = () => {
@@ -52,6 +53,7 @@ const App: Component = () => {
5253
<Route path="/faq" element={<FAQ />} />
5354
<Route path="/problem" element={<Problem />} />
5455
<Route path="/statistics" element={<Stats />} />
56+
<Route path="/status" element={<Status />} />
5557
<Route path="/*" element={<Error />} />
5658
</Route>
5759
<Route path="/sign-up" element={localStorage.getItem('token') !== null && localStorage.getItem('token') !== undefined ? <MainLayout children={<ListProblems/>}/> : <SignUp /> } />

Client/src/data/monaco-syntax/powershell/powershell.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@ export const language = {
258258
[/[\.#]/, 'comment']
259259
]
260260
}
261-
};
261+
};

Client/src/pages/FAQ.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ const FAQ: Component = () => {
138138
<li>The version of Prolog, is the version of SWI-Prolog</li>
139139
</ul>
140140
},
141+
{
142+
question: "Is this language working ?",
143+
answer: <span>
144+
Sometimes, language can be slow or have a problem and don't work..<br/>
145+
You can see the state of every language here: <A href="/status">here</A>
146+
</span>
147+
},
141148
];
142149

143150

@@ -216,4 +223,4 @@ const FAQ: Component = () => {
216223

217224

218225

219-
export default FAQ;
226+
export default FAQ;

Client/src/pages/Status.tsx

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { For, createSignal, onMount } from "solid-js";
2+
import "../style/Status.scss";
3+
import formatLang from "../data/formatLang.json";
4+
5+
6+
const formatMs = (time: number) => time === -1 ? "DOWN" : time > 1000 ? `${(time / 1000).toFixed(3)}s` : `${Math.round(time)}ms`;
7+
const getHue = (time: number) =>
8+
Math.max(
9+
0,
10+
Math.round(
11+
200 + (-(Math.pow(Math.log10(time * 60 + 5e-4 ), 3)))
12+
)
13+
) +
14+
Math.max(
15+
0,
16+
Math.round((1000 - time) / 50)
17+
);
18+
19+
const Status = () => {
20+
21+
const [status, setStatus] = createSignal<{[key: string]: number}>({});
22+
23+
onMount(() => {
24+
fetch("https://api.weekgolf.net/api/v1/status")
25+
.then(rep => rep.json())
26+
.then(rep => setStatus(rep));
27+
});
28+
29+
30+
31+
return <table class="Status">
32+
<tbody>
33+
<For each={Object.keys(status()).filter(l => l !== "node")}>
34+
{
35+
l => {
36+
const ms = status()[l]
37+
38+
return <tr>
39+
<td>
40+
{
41+
(formatLang as {[key: string]: string})[
42+
l
43+
]
44+
}
45+
</td>
46+
<td
47+
style={{
48+
"background-color": `hsl(${getHue(ms < 0 ? 60_000 : ms)}, 100%, ${ms < 0 ? 25 : Math.round(Math.max(30, 50 - ms / 1000))}%)`
49+
}}
50+
>
51+
<b>{formatMs(status()[l])}</b>
52+
</td>
53+
</tr>
54+
}
55+
}
56+
</For>
57+
</tbody>
58+
</table>
59+
}
60+
61+
62+
export default Status;

Client/src/style/Status.scss

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@import "./Variables.scss";
2+
3+
.Status {
4+
margin-block: 30px;
5+
width: 90vw;
6+
margin-left: 5vw;
7+
background-color: #000;
8+
border-radius: 10px;
9+
overflow: hidden;
10+
11+
tr {
12+
td {
13+
&:nth-child(1) {
14+
width: 200px;
15+
background-color: $darken-bg-color-3;
16+
font-weight: 600;
17+
padding-block: 4px;
18+
}
19+
&:nth-child(2) {
20+
color: #000;
21+
}
22+
}
23+
24+
&:hover {
25+
filter: brightness(140%);
26+
}
27+
28+
transition: 0.6s;
29+
}
30+
}

Client/src/utils/defaultCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,4 @@ object p {
328328
};
329329

330330

331-
export default dic;
331+
export default dic;

Discord/formatLang.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"sql": "SQL",
3838
"go": "Go",
3939
"fs": "F#",
40+
"fsharp": "F#",
4041
"f#": "F#",
4142
"groovy": "Groovy",
4243
"dart": "Dart",
@@ -66,4 +67,4 @@
6667
"sass": "Sass",
6768
"erlang": "Erlang",
6869
"delphi": "Delphi"
69-
}
70+
}
File renamed without changes.
File renamed without changes.

Docker/server.ts

+13
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ const waitForFile = (path: string, callback: Function,) => {
8686

8787

8888
// Create the app
89+
//// Get the versions
90+
app.get('/versions', async (req: Request, res: Response) => {
91+
const data = await readFileContents("versions.json");
92+
res.send(data);
93+
});
94+
95+
//// Get the status of languages
96+
app.get("/status", async (req: Request, res: Response) => {
97+
const data = await readFileContents("status.json");
98+
res.send(data);
99+
});
100+
101+
//// Post a language
89102
app.post('/', async (req: Request, res: Response) => {
90103
// Extract the data
91104
let { lang, code, inputs } = req.body;

Docker/status.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"apl": 438.92,
3+
"bash": 271.87,
4+
"bqn": 291.89,
5+
"c": 410.4,
6+
"clojure": 4754.94,
7+
"cpp": 734.99,
8+
"csharp": 4209.05,
9+
"elixir": 57184.72,
10+
"erlang": -1,
11+
"fsharp": 4106.5,
12+
"go": 3022.94,
13+
"golfscript": -1,
14+
"haskell": 1466.72,
15+
"j": -1,
16+
"java": 3964.27,
17+
"javascript": 627.44,
18+
"jelly": -1,
19+
"julia": 1771.77,
20+
"k": 328.07,
21+
"kotlin": 4994.98,
22+
"lua": 287.38,
23+
"node": 668.78,
24+
"ocaml": 331.35,
25+
"perl": 295.42,
26+
"php": 376.46,
27+
"powershell": 3608.19,
28+
"prolog": 676.26,
29+
"python": 380.82,
30+
"r": 2206.19,
31+
"raku": 2044.03,
32+
"ruby": 830.17,
33+
"rust": 875.8,
34+
"sass": 3674.53,
35+
"scala": -1,
36+
"vyxal": 3603.71
37+
}

Docker/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cd test
1414
cp ../$lang/launch.sh .
1515

1616
# Add the program to test to the file
17-
echo $testprogram > "prog.$ext"
17+
echo -e "$testprogram" > "prog.$ext"
1818

1919

2020
# Create files with random values

Docker/test_all.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def unit(n):
1414
else:
1515
return f"{round(n*1000,2)}ms"
1616

17+
status = {}
1718
for k,_ in dic.items():
1819
start_time = time()
1920
result = run(['./test.sh', k], capture_output=True, text=True)
@@ -24,4 +25,8 @@ def unit(n):
2425
else:
2526
print("DOWN",k)
2627

27-
# print(result)
28+
status[k] = round((end_time - start_time) * 1000, 2) if "SUCCESS" in result.stdout else -1
29+
30+
json.dump
31+
json.dump(status, open("status.json", 'w'), indent=4)
32+
# print(result)

Server/src/api/v1/routes/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { verifyToken } from '../middleware/verifyToken';
1111
import { authObligatory } from '../middleware/authObligatory';
1212
//// Routes
1313
import passport from './auth';
14-
import { getLangs, getPersonnalUpvotes, getPhase, submitLanguage, voteLanguage } from './lang';
14+
import { getLangs, getPersonnalUpvotes, getPhase, getStatus, submitLanguage, voteLanguage } from './lang';
1515
import { getLastProblem, getPersonalNote, getProblem, getProblems, getPublicNoteProblem, noteProblem, updateRank } from './problems';
1616
import { getCodeStats, getHistory, getPreviousSolution, getSolution, getSolutions, submitSolution } from './solutions';
1717
import { createAccountRequest, getActivity, getCommentsOfUser, getId, getName, getPerformances, getPfp, getProfile, getUsers, login, updateInfo, verifyCode } from './user';
@@ -148,6 +148,7 @@ router.get('/api/v1/phase', rate1m16req, getPhase);
148148
router.post('/api/v1/submit-language', authObligatory, rate1m16req, submitLanguage);
149149
router.post('/api/v1/vote-language', authObligatory, rate1m64req, rate10m256req, rate1h1024req, voteLanguage);
150150
router.get('/api/v1/personnal-upvotes', rate1m16req, getPersonnalUpvotes);
151+
router.get('/api/v1/status', rate1m8req, getStatus);
151152
// User
152153
router.get('/api/v1/pfp', rate1m64req, getPfp);
153154
router.post('/api/v1/login', rate1m8req, rate10m64req, login);

Server/src/api/v1/routes/lang.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Request, Response } from "express";
1+
import { Request, Response, } from "express";
22
import conn from "../../../config/initDB";
33
import { AuthenticatedRequest } from "../middleware/verifyToken";
44
import sqlExec from "../utils/sqlExec";
5-
5+
import { request } from "request-promise";
6+
import axios from "axios";
67

78

89
/**
@@ -598,3 +599,27 @@ export const getPersonnalUpvotes = async (req: AuthenticatedRequest, res: Respo
598599

599600
res.json(languages.map((langJSON: languagesJSONType) => langJSON.lang));
600601
}
602+
603+
604+
605+
606+
607+
export const getStatus = async (req: AuthenticatedRequest, res: Response): Promise<void> => {
608+
609+
610+
// Define the URL that we want to write to
611+
const requestURL: string = "http://217.69.14.183/status";
612+
//const requestURL: string = "http://localhost:5800/status"
613+
614+
const options = {
615+
method: 'GET',
616+
url: requestURL,
617+
};
618+
619+
await axios(options)
620+
.then(response => {
621+
console.log(response);
622+
console.log(response.data);
623+
res.json(response.data);
624+
})
625+
}

Server/src/config/initDB.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ console.log({
1919
const conn = mysql.createConnection({
2020
host: "127.0.0.1",
2121
user: "root",
22-
password: "testtest",
23-
database: "weekgolfdev",
22+
password: "root",
23+
database: "weekgolf",
2424
multipleStatements: true
2525
});
2626

Server/src/db/sample.sql

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)