This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path_example.ts
71 lines (64 loc) · 1.59 KB
/
_example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Imports */
import axios from "axios";
import { FetchedQuestion, Platform } from "../types";
/* Definitions */
const platformName = "example";
const endpoint = "https://example.com/";
/* Support functions */
async function fetchData() {
let response = await axios({
url: endpoint,
method: "GET",
headers: {
"Content-Type": "text/html",
},
}).then((response) => response.data);
// console.log(response)
return response;
}
async function processPredictions(predictions: any[]) {
const results = await predictions.map((prediction) => {
const id = `${platformName}-${prediction.id}`;
const probability = prediction.probability;
const options: FetchedQuestion["options"] = [
{
name: "Yes",
probability: probability,
type: "PROBABILITY",
},
{
name: "No",
probability: 1 - probability,
type: "PROBABILITY",
},
];
const result: FetchedQuestion = {
id,
title: prediction.title,
url: "https://example.com",
description: prediction.description,
options,
qualityindicators: {
// other: prediction.otherx,
// indicators: prediction.indicatorx,
},
};
return result;
});
return results; //resultsProcessed
}
/* Body */
export const example: Platform = {
name: platformName,
label: "Example platform",
color: "#ff0000",
version: "v1",
async fetcher() {
const data = await fetchData();
const results = await processPredictions(data); // somehow needed
return results;
},
calculateStars(data) {
return 2;
},
};