Fixed bug in addToHistory function
This commit is contained in:
parent
3841dbfd1a
commit
abc4f61432
|
@ -16,7 +16,7 @@ async function fetchAllContractInfo(){ // for info which the polymarket graphql
|
|||
}
|
||||
*/
|
||||
async function fetchAllContractInfo() { // for info which the polymarket graphql API
|
||||
let response = await axios.get('https://strapi-matic.poly.market/markets?active=true&_sort=volume:desc')
|
||||
let response = await axios.get('https://strapi-matic.poly.market/markets?active=true&_sort=volume:desc&_limit=-1')
|
||||
.then(query => query.data);
|
||||
response = response.filter(res => res.closed != true)
|
||||
return response
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { mongoRead, upsert } from "./mongo-wrapper.js"
|
||||
|
||||
import { writeFileSync } from "fs"
|
||||
import { mongoReadWithReadCredentials, upsert } from "./mongo-wrapper.js"
|
||||
let mongoRead = mongoReadWithReadCredentials
|
||||
let isEmptyArray = arr => arr.length == 0
|
||||
export async function addToHistory(){
|
||||
let currentJSON = await mongoRead("metaforecasts")
|
||||
|
@ -16,21 +17,27 @@ export async function addToHistory(){
|
|||
// Add both types of forecast
|
||||
let newHistoryJSON = []
|
||||
for(let historyElement of historyJSON){
|
||||
let correspondingNewElement = currentForecastsWithAHistory.filter(element => historyElement.title == element.title && historyElement.url == element.url )[0]
|
||||
let timeStampOfNewElement = correspondingNewElement.timestamp
|
||||
let doesHistoryAlreadyContainElement = historyElement.history.map(element => element.timestamp).includes(timeStampOfNewElement)
|
||||
if(!doesHistoryAlreadyContainElement){
|
||||
let historyWithNewElement = historyElement["history"].concat({
|
||||
"timestamp": correspondingNewElement.timestamp,
|
||||
"options": correspondingNewElement.options,
|
||||
"qualityindicators": correspondingNewElement.qualityindicators
|
||||
})
|
||||
let newHistoryElement = {...historyElement, "history": historyWithNewElement}
|
||||
newHistoryJSON.push(newHistoryElement)
|
||||
let correspondingNewElementArray = currentForecastsWithAHistory.filter(element => historyElement.title == element.title && historyElement.url == element.url )
|
||||
// console.log(correspondingNewElement)
|
||||
if(!isEmptyArray(correspondingNewElementArray)){
|
||||
let correspondingNewElement = correspondingNewElementArray[0]
|
||||
let timeStampOfNewElement = correspondingNewElement.timestamp
|
||||
let doesHistoryAlreadyContainElement = historyElement.history.map(element => element.timestamp).includes(timeStampOfNewElement)
|
||||
if(!doesHistoryAlreadyContainElement){
|
||||
let historyWithNewElement = historyElement["history"].concat({
|
||||
"timestamp": correspondingNewElement.timestamp,
|
||||
"options": correspondingNewElement.options,
|
||||
"qualityindicators": correspondingNewElement.qualityindicators
|
||||
})
|
||||
let newHistoryElement = {...historyElement, "history": historyWithNewElement}
|
||||
newHistoryJSON.push(newHistoryElement)
|
||||
}else{
|
||||
newHistoryJSON.push(historyElement)
|
||||
}
|
||||
}else{
|
||||
newHistoryJSON.push(historyElement)
|
||||
// console.log(historyElement)
|
||||
newHistoryJSON.push(historyElement)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(let currentForecast of currentForecastsWithoutAHistory){
|
||||
|
@ -46,12 +53,13 @@ export async function addToHistory(){
|
|||
}
|
||||
|
||||
upsert(newHistoryJSON, "metaforecast_history")
|
||||
console.log(newHistoryJSON.slice(0,5))
|
||||
// console.log(newHistoryJSON.slice(0,5))
|
||||
// writeFileSync("metaforecast_history.json", JSON.stringify(newHistoryJSON, null, 2))
|
||||
// writefile(JSON.stringify(newHistoryJSON, null, 2), "metaforecasts_history", "", ".json")
|
||||
//console.log(newHistoryJSON)
|
||||
/*
|
||||
|
||||
let forecastsAlreadyInHistory = currentJSON.filter(element => !isEmptyArray(historyJSON.filter(historyElement => historyElement.title == element.title && historyElement.url == element.url )))
|
||||
*/
|
||||
console.log(new Date().toISOString())
|
||||
}
|
||||
addToHistory()
|
||||
// addToHistory()
|
||||
|
|
Loading…
Reference in New Issue
Block a user