-
Notifications
You must be signed in to change notification settings - Fork 6
/
fantasyscotus.ts
125 lines (114 loc) · 4.12 KB
/
fantasyscotus.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* Imports */
import axios from "axios";
import { FetchedQuestion, Platform } from "./";
const platformName = "fantasyscotus";
/* Definitions */
let unixtime = new Date().getTime();
let endpoint = `https://fantasyscotus.net/case/list/?filterscount=0&groupscount=0&pagenum=0&pagesize=20&recordstartindex=0&recordendindex=12&_=${unixtime}`;
async function fetchData() {
let response = await axios({
method: "GET",
url: endpoint,
headers: {
"User-Agent":
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
Accept: "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/x-www-form-urlencoded",
"X-Requested-With": "XMLHttpRequest",
},
// referrer: "https://fantasyscotus.net/case/list/",
// credentials: "omit",
// mode: "cors",
}).then((res) => res.data);
return response;
}
async function getPredictionsData(caseUrl: string) {
let newCaseUrl = `https://fantasyscotus.net/user-predictions${caseUrl}?filterscount=0&groupscount=0&sortdatafield=username&sortorder=asc&pagenum=0&pagesize=20&recordstartindex=0&recordendindex=20&_=${unixtime}`;
//console.log(newCaseUrl)
let predictions = await axios({
method: "GET",
url: newCaseUrl,
headers: {
"User-Agent":
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
Accept: "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/x-www-form-urlencoded",
"X-Requested-With": "XMLHttpRequest",
},
// referrer: newCaseUrl,
// credentials: "include",
// mode: "cors",
}).then((res) => res.data);
let predictionsAffirm = predictions.filter(
(prediction: any) => prediction.percent_affirm > 50
);
//console.log(predictions)
//console.log(predictionsAffirm.length/predictions.length)
return {
numAffirm: predictionsAffirm.length,
proportionAffirm: predictionsAffirm.length / predictions.length,
numForecasts: predictions.length,
};
}
async function processData(data: any) {
let events = data.object_list;
let historicalPercentageCorrect = data.stats.pcnt_correct;
let historicalProbabilityCorrect =
Number(historicalPercentageCorrect.replace("%", "")) / 100;
let results: FetchedQuestion[] = [];
for (let event of events) {
if (event.accuracy == "") {
let id = `${platformName}-${event.id}`;
// if the thing hasn't already resolved
let predictionData = await getPredictionsData(event.docket_url);
let pAffirm = predictionData.proportionAffirm;
//let trackRecord = event.prediction.includes("Affirm") ? historicalProbabilityCorrect : 1-historicalProbabilityCorrect
let eventObject: FetchedQuestion = {
id: id,
title: `In ${event.short_name}, the SCOTUS will affirm the lower court's decision`,
url: `https://fantasyscotus.net/user-predictions${event.docket_url}`,
description: `${(pAffirm * 100).toFixed(2)}% (${
predictionData.numAffirm
} out of ${
predictionData.numForecasts
}) of FantasySCOTUS players predict that the lower court's decision will be affirmed. FantasySCOTUS overall predicts an outcome of ${
event.prediction
}. Historically, FantasySCOTUS has chosen the correct side ${historicalPercentageCorrect} of the time.`,
options: [
{
name: "Yes",
probability: pAffirm,
type: "PROBABILITY",
},
{
name: "No",
probability: 1 - pAffirm,
type: "PROBABILITY",
},
],
qualityindicators: {
numforecasts: Number(predictionData.numForecasts),
},
};
results.push(eventObject);
}
}
return results;
}
/* Body */
export const fantasyscotus: Platform = {
name: platformName,
label: "FantasySCOTUS",
color: "#231149",
version: "v1",
async fetcher() {
let rawData = await fetchData();
let results = await processData(rawData);
return results;
},
calculateStars(data) {
return 2;
},
};