A bunch of stuff

This commit is contained in:
Alex 2020-11-05 16:22:14 -05:00
parent c21b5beaad
commit ea0f054ee5
5 changed files with 148 additions and 73 deletions

View File

@ -1,54 +0,0 @@
export const allStates = [
"US",
"AK",
"AL",
"AR",
"AZ",
"CA",
"CO",
"CT",
"DC",
"DE",
"FL",
"GA",
"HI",
"IA",
"ID",
"IL",
"IN",
"KS",
"KY",
"LA",
"MA",
"MD",
"ME",
"MI",
"MN",
"MO",
"MS",
"MT",
"NC",
"ND",
"NE",
"NH",
"NJ",
"NM",
"NV",
"NY",
"OH",
"OK",
"OR",
"PA",
"RI",
"SC",
"SD",
"TN",
"TX",
"UT",
"VA",
"VT",
"WA",
"WI",
"WV",
"WY",
];

View File

@ -1,14 +1,18 @@
import fs from "fs";
import {votes} from "./stateData.js";
export async function generateCallManifest(
data = {
// "NA": {
// "winner": "NODATA",
// "resultNow": "0",
// "resultBlock": "0"
// }
},
"NA": {
"winner": "NODATA",
"resultNow": "0",
"resultBlock": "0"
}
}
,
location = "manifest.txt") {
let manifest = fs.createWriteStream(location,)
let now = new Date(Date.now())
@ -16,7 +20,7 @@ export async function generateCallManifest(
"TheElector: automated election call reporting system\n" +
"-----------\n" +
"MANIFEST DATA\n" +
"Generated: " + (now.getMonth() + 1) + "/" + now.getDay() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + " Hours local\n" +
"Generated: " + (now.getMonth() + 1) + "/" + (now.getDay() + 1) + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + " Hours local\n" +
"-----------\n"
)
@ -27,11 +31,27 @@ export async function generateCallManifest(
manifest.write("State: " + state + "\n");
manifest.write("Call: " + data[state].winner + "\n");
manifest.write("Time called: " + (time.getMonth() + 1) + "/" + time.getDay() + " " +
manifest.write("Time called: " + (time.getMonth() + 1) + "/" + (time.getDay() + 1) + " " +
time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() + "\n");
manifest.write("-----------" + "\n");
}
// Counts up votes per side
manifest.write("VOTES PER SIDE: \n")
let trump = 0;
let biden = 0;
for (const state in data) {
if (data[state].winner === "Trump")
trump = trump + votes[state]
if (data[state].winner === "Biden")
biden = biden + votes[state]
}
manifest.write("BIDEN:" + biden + "\n")
manifest.write("TRUMP:" + trump + "\n")
manifest.write("-----------" + "\n")
//end of file
manifest.write("Election data provided by the Associated Press")
manifest.close()
}

View File

@ -1,8 +1,8 @@
import config from "../config.json"
import Web3 from "web3";
import {abi} from "./abi.js";
import {allStates} from "./all-states.js";
import _ from "lodash"
import config from "../config.json"
import {stateList} from "./stateData.js";
const web3 = new Web3(
new Web3.providers.HttpProvider(
config.url
@ -14,15 +14,15 @@ const mainnetContract = new web3.eth.Contract(abi, mainnetAddress);
export async function fetchAllData(exclude = ["NA"]) {
// Excludes areas from data fetching
let stateFetch = allStates;
if (exclude !== ["NA"])
for (let toExclude = 0; toExclude <= exclude.length; toExclude++) {
stateFetch = _.remove(stateFetch, exclude[toExclude])
}
let stateFetch = stateList;
// if (exclude !== ["NA"])
// for (let toExclude = 0; toExclude <= exclude.length; toExclude++) {
// stateFetch = _.remove(stateFetch, exclude[toExclude])
// }
let allWins = {}
for (let i = 0; i <= stateFetch.length - 1; i++) {
let state = allStates[i];
let state = stateList[i];
allWins[state] = await mainnetContract.methods
.presidentialWinners(state)
.call()

109
data/stateData.js Normal file
View File

@ -0,0 +1,109 @@
export const stateList = [
"US",
"AK",
"AL",
"AR",
"AZ",
"CA",
"CO",
"CT",
"DC",
"DE",
"FL",
"GA",
"HI",
"IA",
"ID",
"IL",
"IN",
"KS",
"KY",
"LA",
"MA",
"MD",
"ME",
"MI",
"MN",
"MO",
"MS",
"MT",
"NC",
"ND",
"NE",
"NH",
"NJ",
"NM",
"NV",
"NY",
"OH",
"OK",
"OR",
"PA",
"RI",
"SC",
"SD",
"TN",
"TX",
"UT",
"VA",
"VT",
"WA",
"WI",
"WV",
"WY",
];
export const votes = {
"US": 0,
"CA": 55,
"TX": 38,
"FL": 29,
"NY": 29,
"IL": 20,
"PA": 20,
"OH": 18,
"GA": 16,
"MI": 16,
"NC": 15,
"NJ": 14,
"VA": 13,
"WA": 12,
"AZ": 11,
"IN": 11,
"MA": 11,
"TN": 11,
"MD": 10,
"MN": 10,
"MO": 10,
"WI": 10,
"AL": 9,
"CO": 9,
"SC": 9,
"KY": 8,
"LA": 8,
"CT": 7,
"OK": 7,
"OR": 7,
"AR": 6,
"IA": 6,
"KS": 6,
"MS": 6,
"NV": 6,
"UT": 6,
"NE": 5,
"NM": 5,
"WV": 5,
"HI": 4,
"ID": 4,
"ME": 4,
"NH": 4,
"RI": 4,
"AK": 3,
"DC": 3,
"DE": 3,
"MT": 3,
"ND": 3,
"SD": 3,
"VT": 3,
"WY": 3,
}

View File

@ -9,10 +9,10 @@ await fetchCalls().then((results) => {
fs.writeFile("calls.json", data, () => {
console.log("Calls written to file")
})
generateCallManifest(results).then(() => (console.log("Manifest created")))
})