Process en data

pull/10/head
sigonasr2 3 years ago
parent 73986c614f
commit ef9d324cc8
  1. 109
      frontend/package-lock.json
  2. 2
      frontend/package.json
  3. 315
      frontend/src/App.js
  4. 21
      frontend/src/setupProxy.js
  5. 572
      server/app.js
  6. 1955
      server/app.js.save

@ -1361,6 +1361,11 @@
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.4.4.tgz", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.4.4.tgz",
"integrity": "sha512-1oO6+dN5kdIA3sKPZhRGJTfGVP4SWV6KqlMOwry4J3HfyD68sl/3KmG7DeYUzvN+RbhXDnv/D8vNNB8168tAMg==" "integrity": "sha512-1oO6+dN5kdIA3sKPZhRGJTfGVP4SWV6KqlMOwry4J3HfyD68sl/3KmG7DeYUzvN+RbhXDnv/D8vNNB8168tAMg=="
}, },
"@reach/observe-rect": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@reach/observe-rect/-/observe-rect-1.2.0.tgz",
"integrity": "sha512-Ba7HmkFgfQxZqqaeIWWkNK0rEhpxVQHIoVyW1YDSkGsGIXzcaW4deC8B0pZrNSSyLTdIk7y+5olKt5+g0GmFIQ=="
},
"@restart/context": { "@restart/context": {
"version": "2.1.4", "version": "2.1.4",
"resolved": "https://registry.npmjs.org/@restart/context/-/context-2.1.4.tgz", "resolved": "https://registry.npmjs.org/@restart/context/-/context-2.1.4.tgz",
@ -3710,6 +3715,11 @@
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==" "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg=="
}, },
"components": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/components/-/components-0.1.0.tgz",
"integrity": "sha1-IFfAjpx78mYv7slcSeX/Kpq4XtU="
},
"compose-function": { "compose-function": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/compose-function/-/compose-function-3.0.3.tgz", "resolved": "https://registry.npmjs.org/compose-function/-/compose-function-3.0.3.tgz",
@ -4273,6 +4283,83 @@
"type": "^1.0.1" "type": "^1.0.1"
} }
}, },
"d3-array": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-2.11.0.tgz",
"integrity": "sha512-26clcwmHQEdsLv34oNKq5Ia9tQ26Y/4HqS3dQzF42QBUqymZJ+9PORcN1G52bt37NsL2ABoX4lvyYZc+A9Y0zw==",
"requires": {
"internmap": "^1.0.0"
}
},
"d3-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/d3-color/-/d3-color-2.0.0.tgz",
"integrity": "sha512-SPXi0TSKPD4g9tw0NMZFnR95XVgUZiBH+uUTqQuDu1OsE2zomHU7ho0FISciaPvosimixwHFl3WHLGabv6dDgQ=="
},
"d3-delaunay": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/d3-delaunay/-/d3-delaunay-5.3.0.tgz",
"integrity": "sha512-amALSrOllWVLaHTnDLHwMIiz0d1bBu9gZXd1FiLfXf8sHcX9jrcj81TVZOqD4UX7MgBZZ07c8GxzEgBpJqc74w==",
"requires": {
"delaunator": "4"
}
},
"d3-format": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/d3-format/-/d3-format-2.0.0.tgz",
"integrity": "sha512-Ab3S6XuE/Q+flY96HXT0jOXcM4EAClYFnRGY5zsjRGNy6qCYrQsMffs7cV5Q9xejb35zxW5hf/guKw34kvIKsA=="
},
"d3-interpolate": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-2.0.1.tgz",
"integrity": "sha512-c5UhwwTs/yybcmTpAVqwSFl6vrQ8JZJoT5F7xNFK9pymv5C0Ymcc9/LIJHtYIggg/yS9YHw8i8O8tgb9pupjeQ==",
"requires": {
"d3-color": "1 - 2"
}
},
"d3-path": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/d3-path/-/d3-path-1.0.9.tgz",
"integrity": "sha512-VLaYcn81dtHVTjEHd8B+pbe9yHWpXKZUC87PzoFmsFrJqgFwDe/qxfp5MlfsfM1V5E/iVt0MmEbWQ7FVIXh/bg=="
},
"d3-scale": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-3.2.3.tgz",
"integrity": "sha512-8E37oWEmEzj57bHcnjPVOBS3n4jqakOeuv1EDdQSiSrYnMCBdMd3nc4HtKk7uia8DUHcY/CGuJ42xxgtEYrX0g==",
"requires": {
"d3-array": "^2.3.0",
"d3-format": "1 - 2",
"d3-interpolate": "1.2.0 - 2",
"d3-time": "1 - 2",
"d3-time-format": "2 - 3"
}
},
"d3-shape": {
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-1.3.7.tgz",
"integrity": "sha512-EUkvKjqPFUAZyOlhY5gzCxCeI0Aep04LwIRpsZ/mLFelJiUfnK56jo5JMDSE7yyP2kLSb6LtF+S5chMk7uqPqw==",
"requires": {
"d3-path": "1"
}
},
"d3-time": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/d3-time/-/d3-time-2.0.0.tgz",
"integrity": "sha512-2mvhstTFcMvwStWd9Tj3e6CEqtOivtD8AUiHT8ido/xmzrI9ijrUUihZ6nHuf/vsScRBonagOdj0Vv+SEL5G3Q=="
},
"d3-time-format": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/d3-time-format/-/d3-time-format-3.0.0.tgz",
"integrity": "sha512-UXJh6EKsHBTjopVqZBhFysQcoXSv/5yLONZvkQ5Kk3qbwiUYkdX17Xa1PT6U1ZWXGGfB1ey5L8dKMlFq2DO0Ag==",
"requires": {
"d3-time": "1 - 2"
}
},
"d3-voronoi": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/d3-voronoi/-/d3-voronoi-1.1.4.tgz",
"integrity": "sha512-dArJ32hchFsrQ8uMiTBLq256MpnZjeuBtdHpaDlYuQyjU0CVzCJl/BVW+SkszaAeH95D/8gxqAhgx0ouAWAfRg=="
},
"damerau-levenshtein": { "damerau-levenshtein": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.6.tgz", "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.6.tgz",
@ -4448,6 +4535,11 @@
} }
} }
}, },
"delaunator": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/delaunator/-/delaunator-4.0.1.tgz",
"integrity": "sha512-WNPWi1IRKZfCt/qIDMfERkDp93+iZEmOxN2yy4Jg+Xhv8SLk2UTqqbe1sfiipn0and9QrE914/ihdx82Y/Giag=="
},
"delayed-stream": { "delayed-stream": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
@ -6849,6 +6941,11 @@
"side-channel": "^1.0.2" "side-channel": "^1.0.2"
} }
}, },
"internmap": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/internmap/-/internmap-1.0.0.tgz",
"integrity": "sha512-SdoDWwNOTE2n4JWUsLn4KXZGuZPjPF9yyOGc8bnfWnBQh7BD/l80rzSznKc/r4Y0aQ7z3RTk9X+tV4tHBpu+dA=="
},
"invariant": { "invariant": {
"version": "2.2.4", "version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
@ -10573,6 +10670,18 @@
"prop-types": "^15.7.2" "prop-types": "^15.7.2"
} }
}, },
"react-charts": {
"version": "2.0.0-beta.7",
"resolved": "https://registry.npmjs.org/react-charts/-/react-charts-2.0.0-beta.7.tgz",
"integrity": "sha512-iUspg9rnx7kD0H/wsK67HNUioOgKgJ8WRXr/Tk3EGP2qcFb9Vo7pjDk4oz1jH12TC+mqL+HFxNYraMkhWd6CUw==",
"requires": {
"@reach/observe-rect": "^1.1.0",
"d3-delaunay": "^5.2.1",
"d3-scale": "^3.2.1",
"d3-shape": "^1.3.7",
"d3-voronoi": "^1.1.2"
}
},
"react-dev-utils": { "react-dev-utils": {
"version": "10.2.1", "version": "10.2.1",
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-10.2.1.tgz", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-10.2.1.tgz",

@ -9,11 +9,13 @@
"@testing-library/user-event": "^7.2.1", "@testing-library/user-event": "^7.2.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"chart.js": "^2.9.4", "chart.js": "^2.9.4",
"components": "^0.1.0",
"http-proxy-middleware": "^1.0.5", "http-proxy-middleware": "^1.0.5",
"moment": "^2.29.0", "moment": "^2.29.0",
"react": "^16.13.1", "react": "^16.13.1",
"react-bootstrap": "^1.3.0", "react-bootstrap": "^1.3.0",
"react-chartjs-2": "^2.11.1", "react-chartjs-2": "^2.11.1",
"react-charts": "^2.0.0-beta.7",
"react-dom": "^16.13.1", "react-dom": "^16.13.1",
"react-router-dom": "^5.2.0", "react-router-dom": "^5.2.0",
"react-router-hash-link": "^2.1.0", "react-router-hash-link": "^2.1.0",

@ -1,3 +1,5 @@
import { Chart } from 'react-charts'
import React, {useState,useEffect,useRef} from 'react'; import React, {useState,useEffect,useRef} from 'react';
import logo from './logo.svg'; import logo from './logo.svg';
import './App.css'; import './App.css';
@ -2224,7 +2226,7 @@ function EventEditor() {
const[send,setSend] = useState(false) const[send,setSend] = useState(false)
const[message,setMessage] = useState("") const[message,setMessage] = useState("")
const EVENTID = 10; const EVENTID = 17;
//console.log(moment().format("YYYY-MM-DDTHH:mm")) //console.log(moment().format("YYYY-MM-DDTHH:mm"))
@ -2311,246 +2313,89 @@ function EventEditor() {
</> </>
} }
function ChartData() { function CanEditor() {
const[eventData,setEventData] = useState([]) const [password,setPassword] = useState("");
const[update,setUpdate] = useState(false) const [cans,setCans] = useState(0);
const [chartData,setChartData] = useState([]) const [games,setGames] = useState(0);
const [update,setUpdate] = useState(false)
useEffect(()=>{ useEffect(()=>{
refreshCount()
const interval = setInterval(()=>{ const interval = setInterval(()=>{
axios.get("http://projectdivar.com/eventdata/t20") refreshCount()
.then((data)=>{ },5000);
var values;
data.data.map((obj)=>{if (values[obj.rank]) {values[obj.rank]=[...values[obj.rank],obj]} else {values[obj.rank]=[obj]}})
setEventData(values);
console.log(data.data)
})
.catch((err)=>{})
},30000);
return ()=>{clearInterval(interval)} return ()=>{clearInterval(interval)}
},[update]) },[update])
useEffect(()=>{ useEffect(()=>{
console.log(eventData)
setChartData( },[password])
{
datasets: [{ function refreshCount() {
label: 'T1', axios.get("http://projectdivar.com/cans")
data: GetChartData(eventData,1), .then((data)=>{
backgroundColor: [ if (data.data.cans>cans) {
'rgba(255, 99, 132, 0.05)', setCans(data.data.cans)
'rgba(54, 162, 235, 0.05)',
'rgba(255, 206, 86, 0.05)',
'rgba(75, 192, 192, 0.05)',
'rgba(153, 102, 255, 0.05)',
'rgba(255, 159, 64, 0.05)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
]
},{
label: 'T2',
data: GetChartData(eventData,2),
backgroundColor: [
'rgba(54, 162, 235, 0.05)'
],
borderColor: [
'rgba(54, 162, 235, 1)'
]
},{
label: 'T3',
data: GetChartData(eventData,3),
backgroundColor: [
'rgba(255, 206, 86, 0.05)',
],
borderColor: [
'rgba(255, 206, 86, 1)',
]
},{
label: 'T4',
data: GetChartData(eventData,4),
backgroundColor: [
'rgba(75, 192, 192, 0.05)',
],
borderColor: [
'rgba(75, 192, 192, 1)',
]
},{
label: 'T5',
data: GetChartData(eventData,5),
backgroundColor: [
'rgba(153, 102, 255, 0.05)',
],
borderColor: [
'rgba(153, 102, 255, 1)',
]
},{
label: 'T6',
data: GetChartData(eventData,6),
backgroundColor: [
'rgba(255, 159, 64, 0.05)'
],
borderColor: [
'rgba(255, 159, 64, 1)'
]
},{
label: 'T7',
data: GetChartData(eventData,7),
backgroundColor: [
'rgba(255, 99, 132, 0.05)'
],
borderColor: [
'rgba(255, 99, 132, 1)'
]
},{
label: 'T8',
data: GetChartData(eventData,8),
backgroundColor: [
'rgba(54, 162, 235, 0.05)'
],
borderColor: [
'rgba(54, 162, 235, 1)'
]
},{
label: 'T9',
data: GetChartData(eventData,9),
backgroundColor: [
'rgba(255, 206, 86, 0.05)'
],
borderColor: [
'rgba(255, 206, 86, 1)'
]
},{
label: 'T10',
data: GetChartData(eventData,10),
backgroundColor: [
'rgba(75, 192, 192, 0.05)'
],
borderColor: [
'rgba(75, 192, 192, 1)'
]
},{
label: 'T20',
data: GetChartData(eventData,20),
backgroundColor: [
'rgba(0, 0, 0, 0.05)'
],
borderColor: [
'rgba(0, 0, 0, 1)'
]
},{
label: 'T50',
data: GetChartData(eventData,50),
backgroundColor: [
'rgba(255, 255, 255, 0.5)'
],
borderColor: [
'rgba(255, 255, 255, 1)'
]
} }
,{ if (data.data.cans+data.data.notcan>games) {
label: 'T100', setGames(Number(data.data.cans)+Number(data.data.notcan))
data: GetChartData(eventData,100),
backgroundColor: [
'rgba(150, 255, 150, 0.5)'
],
borderColor: [
'rgba(150, 255, 150, 1)'
]
},{
label: 'T500',
data: GetChartData(eventData,500),
backgroundColor: [
'rgba(160, 0, 0, 0.5)'
],
borderColor: [
'rgba(160, 0, 0, 1)'
]
},{
label: 'T1000',
data: GetChartData(eventData,1000),
backgroundColor: [
'rgba(255, 150, 150, 0.5)'
],
borderColor: [
'rgba(255, 150, 150, 1)'
]
},{
label: 'T5000',
data: GetChartData(eventData,5000),
backgroundColor: [
'rgba(0, 140, 0, 0.5)'
],
borderColor: [
'rgba(0, 140, 0, 1)'
]
},{
label: 'T10000',
data: GetChartData(eventData,10000),
backgroundColor: [
'rgba(30, 30, 255, 0.5)'
],
borderColor: [
'rgba(30, 30, 255, 1)'
]
}/*,{
label: 'T100 HAPPY FORTUNE NEW YEAR',
data: [
{x:moment('2021-01-12 12:00:00+09:00').add(0,'days').add(0,'hours'),y:0},
{x:moment('2021-01-12 12:00:00+09:00').add(0,'days').add(7,'hours'),y:54036},
{x:moment('2021-01-12 12:00:00+09:00').add(4,'days').add(23,'hours'),y:451398},
{x:moment('2021-01-12 12:00:00+09:00').add(5,'days').add(3,'hours'),y:470204},
{x:moment('2021-01-12 12:00:00+09:00').add(7,'days').add(18,'hours'),y:671150},
{x:moment('2021-01-12 12:00:00+09:00').add(8,'days').add(15,'hours'),y:915147},
{x:moment('2021-01-12 12:00:00+09:00').add(8,'days').add(17,'hours'),y:952330},
{x:moment('2021-01-12 12:00:00+09:00').add(8,'days').add(19,'hours'),y:988548},
{x:moment('2021-01-12 12:00:00+09:00').add(8,'days').add(21,'hours'),y:1027488},
],
backgroundColor: [
'rgba(255, 255, 150, 0.5)'
],
borderColor: [
'rgba(255, 255, 150, 1)'
]
}*/],
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'hours',
displayFormats: {
hours: 'MMM D hA'
}
},
ticks: {
min:EVENTSTART,
max:EVENTEND
},
distribution: 'linear'
}]
} }
})
} }
function sendRequest(cans) {
axios.post("http://projectdivar.com/cans",{cans:cans})
.then((data)=>{
refreshCount()
})
} }
)
},[eventData])
return ( function addCan(t) {
<> setCans(Number(cans)+1)
<h1>繋ぎ手たちは導かれ前編</h1> setGames(Number(games)+1)
<Line data={chartData} /> sendRequest(true)
}
function addGame(t) {
setGames(Number(games)+1)
sendRequest(false)
}
return <>
<div className="container">
<div className="row">
<div className="col-12 text-center">
<h3>Can %</h3>
<h1>{((cans/games)*100).toFixed(2)+"%"}</h1>
</div>
</div>
<div className="row">
<div className="col-6 text-center">
<h5>Cans</h5>
<h1>{cans}</h1>
</div>
<div className="col-6 text-center">
<h5>Total Games</h5>
<h1>{games}</h1>
</div>
</div>
</div>
{/*{password!=="muni_62"&&<>
<b>Password to Edit:</b>
<input type="password" placeholder="Password" onChange={(t)=>{
setPassword(t.currentTarget.value)
}}
/></>}
{password=="muni_62"&&<>
<div className="row">
<div className="col-6 text-center">
<button onClick={(t)=>{addGame(t)}}>No Can</button>
</div>
<div className="col-6 text-center">
<button onClick={(t)=>{addCan(t)}}>Can</button>
</div>
</div>
</>}*/}
</> </>
)
} }
function Website() { function Website() {
@ -2570,7 +2415,7 @@ function Website() {
return ( return (
<div className="row"> <div className="row">
{/*<div className="col-md-2 pt-3 pb-3 overflow-hidden text-center"> <div className="col-md-2 pt-3 pb-3 overflow-hidden text-center">
<h3 className="d-none d-md-block">Menu</h3> <h3 className="d-none d-md-block">Menu</h3>
<LoginInfo setUserSettings={setUserSettings} setUsername={setUsername} update={loginPanelUpdate}/> <LoginInfo setUserSettings={setUserSettings} setUsername={setUsername} update={loginPanelUpdate}/>
<br/><br/> <br/><br/>
@ -2579,7 +2424,7 @@ function Website() {
<Link to="/divabot#content">DivaBot</Link><br/> <Link to="/divabot#content">DivaBot</Link><br/>
<hr/> <hr/>
<a href="http://discord.gg/eJ3cMzM"><img src="http://projectdivar.com/files/discord_button_small.png"/></a> <a href="http://discord.gg/eJ3cMzM"><img src="http://projectdivar.com/files/discord_button_small.png"/></a>
</div>*/} </div>
<div className="col-md-10 pt-3 pb-3"> <div className="col-md-10 pt-3 pb-3">
<div id="content"/> <div id="content"/>
<Switch> <Switch>
@ -2621,12 +2466,16 @@ function Website() {
</Route> </Route>
<Route path="/event"> <Route path="/event">
<h1 className="title">Event Data</h1> <h1 className="title">Event Data</h1>
<ChartData/> <EventData/>
</Route> </Route>
<Route path="/eventedit"> <Route path="/eventedit">
<h1 className="title">Event Editor</h1> <h1 className="title">Event Editor</h1>
<EventEditor/> <EventEditor/>
</Route> </Route>
<Route path="/cancount">
<h1 className="title">Can or no Can?</h1>
<CanEditor/>
</Route>
<Route path="/"> <Route path="/">
<h1 className="title">Project DivaR</h1> <h1 className="title">Project DivaR</h1>
Welcome! This website is here to store and track all your Project Diva records for yours and others' enjoyment! Welcome! This website is here to store and track all your Project Diva records for yours and others' enjoyment!
@ -2776,7 +2625,7 @@ function App() {
return ( return (
<Router> <Router>
<div className="container-fluid content"> <div className="container-fluid content">
{/*<div className="row"> <div className="row">
<div className="topbar col-md-12 pt-1 overflow-hidden border rounded text-center"> <div className="topbar col-md-12 pt-1 overflow-hidden border rounded text-center">
<div> <div>
<Link to="/"> <Link to="/">
@ -2784,7 +2633,7 @@ function App() {
</Link> </Link>
</div> </div>
</div> </div>
</div>*/} </div>
<Website/> <Website/>
</div> </div>
</Router> </Router>

@ -1,6 +1,27 @@
const { createProxyMiddleware } = require('http-proxy-middleware'); const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) { module.exports = function(app) {
/*app.use(
"/event/query",
createProxyMiddleware({
target: 'http://server:4501',
changeOrigin: true,
})
);*/
app.use(
"/ev",
createProxyMiddleware({
target: 'http://server:4501',
changeOrigin: true,
})
);
app.use(
"/cans",
createProxyMiddleware({
target: 'http://server:4501',
changeOrigin: true,
})
);
app.use( app.use(
"/eventchart", "/eventchart",
createProxyMiddleware({ createProxyMiddleware({

@ -1,4 +1,4 @@
const express = require('express') const express = require('express')
const axios = require('axios') const axios = require('axios')
const twitchStreams = require('twitch-get-stream') const twitchStreams = require('twitch-get-stream')
const app = express() const app = express()
@ -45,6 +45,29 @@ new Pool({
port: 5432, port: 5432,
}) })
/*const db2 =
new Pool({
user: 'read_only_user',
password: 'divar1234',
host: 'postgres',
database: 'divar',
port: 5432,
})
app.get('/event/query',(req,res)=>{
if (req.query.query&&req.query.query.length>0) {
db2.query(req.query.query)
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).json(err.message)
})
} else {
res.status(400).send("Empty query!")
}
})*/
app.get('/song/:songname', (req, res) => { app.get('/song/:songname', (req, res) => {
db.query('select * from songs where name=$1 or romanized_name=$1 or english_name=$1 limit 1', [req.params.songname] , (error, results) => { db.query('select * from songs where name=$1 or romanized_name=$1 or english_name=$1 limit 1', [req.params.songname] , (error, results) => {
if (error) { if (error) {
@ -1166,15 +1189,28 @@ app.post('/streaminfo/:id',function (req,res){
} }
}) })
const lastscores={} var lastscores={}
const EVENTID=23;
var EVENTSTART=moment('2021-06-28 03:00:00+00');
var EVENTEND=moment('2021-07-06 11:59:59+00');
var lastscores_EN={}
const EVENTID_EN=23;
var EVENTSTART_EN=moment('2021-06-28 03:00:00+00');
var EVENTEND_EN=moment('2021-07-06 11:59:59+00');
app.get("/helpmetestwithoutbreakingshit", (req,res) => {
res.status(200).send("hi")
db.query("select eventid, startdate, enddate from event order by id desc limit 1").then(res.status(200).send)
})
app.post('/eventsubmit',function(req,res) { app.post('/eventsubmit',function(req,res) {
const EVENTID=10;
lastscores={}
function submit() { function submit() {
lastscores[req.body.rank]=Number(req.body.points) lastscores[req.body.rank]=Number(req.body.points)
db.query("insert into eventdata(eventid,rank,date,name,description,points) values($1,$2,$3,$4,$5,$6) returning *;", db.query("insert into "+(req.query.en?"en_":"")+"eventdata(eventid,rank,date,name,description,points) values($1,$2,$3,$4,$5,$6) returning *;",
[req.body.eventid,req.body.rank,req.body.date?req.body.date:new Date(),req.body.name,req.body.description,req.body.points]) [req.body.eventid,req.body.rank,req.body.date?req.body.date:req.body.fin?moment(EVENTEND).add(5,'minutes').format("YYYY-MM-DD HH:mm:ssZ"):new Date(),req.body.name,req.body.description,req.body.points])
.then((data)=>{ .then((data)=>{
if (data.rows.length>0) { if (data.rows.length>0) {
res.status(200).send("Submitted.") res.status(200).send("Submitted.")
@ -1189,8 +1225,59 @@ app.post('/eventsubmit',function(req,res) {
//add to table. //add to table.
function FurtherTierIsOkay(tier,scores,points) {
var tiers= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,50,100,500,1000,2000,5000,10000,20000,30000,50000]
if (tier<=1) {
return true;
} else
{
//Find the previous tier.
var previousTier = -1;
for (var i=0;i<tiers.length;i++) {
if (tiers[i]==tier) {
previousTier=tiers[i-1]
}
}
if (previousTier==-1) {
console.log("Something weird happened....")
return false; //Something terrible happened.
} else
if (!scores[tier]) {
return true; //It's okay since no score is submitted yet.
} else
{
return points<scores[previousTier] //If it's greater something's wrong...
}
}
}
function EndsWithZeroes(str) {
var zeroCount=0;
var string = String(str)
for (var i=0;i<string.length;i++) {
if (string[i]=='0') {
zeroCount++;
} else {
zeroCount=0;
}
}
return zeroCount>=2;
}
function ScoreIsSanitary(rank,name,description,points) {
if (Number(rank)<=20) {
return true;
} else {
if (EndsWithZeroes(name)||EndsWithZeroes(description)||EndsWithZeroes(points)) {
return false;
} else {
return true;
}
}
}
//Try to update last scores. //Try to update last scores.
db.query('select distinct on (rank) rank,eventid,date,name,description,points from eventdata where eventid='+EVENTID+' order by rank,date desc;') db.query('select distinct on (rank) rank,eventid,date,name,description,points,difference from (select lead(points) over (partition by rank order by rank,date desc)-points difference,* from '+(req.query.en?"en_":"")+'eventdata where eventid='+EVENTID+' order by rank,date desc)t order by rank,date desc')
.then((data) => .then((data) =>
{ {
if (data.rows.length>0) { if (data.rows.length>0) {
@ -1198,20 +1285,14 @@ app.post('/eventsubmit',function(req,res) {
} }
if (!lastscores[req.body.rank]||(lastscores[req.body.rank]<req.body.points&& if (!lastscores[req.body.rank]
(req.body.rank>20||req.body.points<lastscores[req.body.rank]+30000) || (/*FurtherTierIsOkay(req.body.rank,lastscores,req.body.points)&&*/lastscores[req.body.rank]<req.body.points
)) { &&(req.body.fin||ScoreIsSanitary(req.body.rank,req.body.name,req.body.description,req.body.points))/*||(lastscores[req.body.rank]<req.body.points
&&(FurtherTierIsOkay(req.body.rank,lastscores,req.body.points))*/))
{
submit() submit()
} else { } else {
if (lastscores[req.body.rank]!==undefined&&req.body.rank<=20&&(lastscores[req.body.rank]<req.body.points&&req.body.points<lastscores[req.body.rank]+30000)) {
res.status(200).send("An invalid score attempted to be uploaded. Expected "+(lastscores[req.body.rank]+30000)+" or less but got "+req.body.points+".")
} else {
if (req.body.rank<=20) {
res.status(200).send("No update required.") res.status(200).send("No update required.")
} else {
submit()
}
}
} }
} }
) )
@ -1219,15 +1300,21 @@ app.post('/eventsubmit',function(req,res) {
var chartData={} var chartData={}
var predictionChartData={} var predictionChartData={}
var EVENTSTART=moment('2021-02-14 12:00:00+09:00');
var EVENTEND=moment('2021-02-22 20:59:59+09:00');
var diffData=[] var diffData=[]
var en_chartData={}
var en_predictionChartData={}
var en_diffData=[]
const PREDICTIONS=true const PREDICTIONS=true
const en_PREDICTIONS=true
var lastCachedDate=EVENTSTART var lastCachedDate=EVENTSTART
var en_lastCachedDate=EVENTSTART
const nyoomfactor={//Percentage of original speed to use when nyoom'ing const nyoomfactor={//Percentage of original speed to use when nyoom'ing
1:1.0, 1:1.0,
@ -1250,16 +1337,17 @@ const nyoomfactor={//Percentage of original speed to use when nyoom'ing
18:0.3, 18:0.3,
19:0.3, 19:0.3,
20:0.3, 20:0.3,
50:0.79, 50:0.81,
100:0.72, 100:0.76,
500:0.25, 500:0.28,
1000:0.2, 1000:0.24,
2000:0.06, 2000:0.09,
5000:0.055, 5000:0.07,
10000:0.015, 10000:0.04,
20000:0.01 20000:0.02
} }
const slowdownFactor={//Percentage of slowdown per hour. const slowdownFactor={//Percentage of slowdown per hour.
1:0.00001, 1:0.00001,
2:0.00003, 2:0.00003,
@ -1285,27 +1373,66 @@ const slowdownFactor={//Percentage of slowdown per hour.
100:0.0003, 100:0.0003,
500:0.0004, 500:0.0004,
1000:0.0005, 1000:0.0005,
2000:0.0007, 2000:0.0005,
5000:0.001, 5000:0.0005,
10000:0.002, 10000:0.0005,
20000:0.003 20000:0.0005
} }
var MAXSPEED=0 var MAXSPEED=0
function SetupPredictionModel() { function SetupPredictionModel() {
if (chartData['1']&&chartData['1'].length>100) { if (chartData['1']&&chartData['1'].length>400) {
MAXSPEED=Math.floor(chartData['1'][100].points/(moment(chartData['1'][100].date).diff(EVENTSTART,'minutes')/60)) MAXSPEED=Math.floor(chartData['1'][400].points/(moment(chartData['1'][400].date).diff(EVENTSTART,'minutes')/60))
} else } else
if (chartData['1']&&chartData['1'].length>0){ if (chartData['1']&&chartData['1'].length>0){
MAXSPEED=Math.floor(chartData['1'][chartData['1'].length-1].points/(moment(chartData['1'][chartData['1'].length-1].date).diff(EVENTSTART,'minutes')/60)) MAXSPEED=Math.floor(chartData['1'][chartData['1'].length-1].points/(moment(chartData['1'][chartData['1'].length-1].date).diff(EVENTSTART,'minutes')/60))
} else { } else {
MAXSPEED=0 MAXSPEED=0
} }
if (en_chartData['1']&&en_chartData['1'].length>400) {
MAXSPEED=Math.floor(en_chartData['1'][400].points/(moment(en_chartData['1'][400].date).diff(EVENTSTART,'minutes')/60))
} else
if (en_chartData['1']&&en_chartData['1'].length>0){
MAXSPEED=Math.floor(en_chartData['1'][en_chartData['1'].length-1].points/(moment(en_chartData['1'][en_chartData['1'].length-1].date).diff(EVENTSTART,'minutes')/60))
} else {
MAXSPEED=0
}
} }
const RATEDURATION=2 //In hours. How much EP/hr is shown. const RATEDURATION=2 //In hours. How much EP/hr is shown.
function GetRate(rank) { function GetRate(rank,en) {
if (en) {
if (en_chartData[rank].length>2) {
var lastpoint=en_chartData[rank][en_chartData[rank].length-1]
for (var i=en_chartData[rank].length-1;i>=0;i--) {
var diff = moment().diff(en_chartData[rank][i].date,'hours')
if (diff>=RATEDURATION) {
break;
} else {
lastpoint=en_chartData[rank][i]
}
}
var timediff = moment(en_chartData[rank][en_chartData[rank].length-1].date).diff(moment(lastpoint.date),'minutes')
if (timediff<120) {
if (lastpoint===en_chartData[rank][en_chartData[rank].length-1]) {
return "???"
} else
return (en_chartData[rank][en_chartData[rank].length-1].points-lastpoint.points)/RATEDURATION
} else {
return Math.ceil((en_chartData[rank][en_chartData[rank].length-1].points-lastpoint.points)/
(moment(en_chartData[rank][en_chartData[rank].length-1].date).diff(moment(lastpoint.date),'minutes')/60)
)
}
} else {
if (en_chartData[rank].length>0) {
var startPoint=en_chartData[rank][en_chartData[rank].length-1]
return Math.ceil(GetRank(rank)/(moment(startPoint.date).diff(EVENTSTART,'minutes')/60))
} else {
return 0
}
}
} else {
if (chartData[rank].length>2) { if (chartData[rank].length>2) {
var lastpoint=chartData[rank][chartData[rank].length-1] var lastpoint=chartData[rank][chartData[rank].length-1]
for (var i=chartData[rank].length-1;i>=0;i--) { for (var i=chartData[rank].length-1;i>=0;i--) {
@ -1335,10 +1462,36 @@ function GetRate(rank) {
return 0 return 0
} }
} }
}
} }
function GetPointCount(rank) { function GetPointCount(rank,en) {
var pointCount=1; var pointCount=1;
if (en) {
if (!en_chartData[rank]) {
return pointCount;
}
if (en_chartData[rank].length>2) {
var lastpoint=en_chartData[rank][en_chartData[rank].length-1]
for (var i=en_chartData[rank].length-1;i>=0;i--) {
var diff = moment().diff(en_chartData[rank][i].date,'hours')
if (diff>=RATEDURATION) {
break;
} else {
lastpoint=en_chartData[rank][i]
pointCount++;
}
}
return pointCount;
} else {
if (en_chartData[rank].length>0) {
return en_chartData[rank].length;
} else {
return pointCount;
}
}
} else
{
if (!chartData[rank]) { if (!chartData[rank]) {
return pointCount; return pointCount;
} }
@ -1361,9 +1514,72 @@ function GetPointCount(rank) {
return pointCount; return pointCount;
} }
} }
}
} }
function CreatePrediction(precision,rank) { function CreatePrediction(precision,rank,en) {
if (en) {
if (!en_chartData[rank]) {
return []
}
var startPoint=en_chartData[rank][en_chartData[rank].length-1]
if (rank<=20) {
startPoint={points:startPoint.points,date:moment()}
}
var startTime=moment(startPoint.date)
if (en_PREDICTIONS&&startTime.diff(EVENTSTART_en,'hours')>36&&moment(startPoint.date).diff(EVENTSTART_en,'hours')>=36) {
//console.log(MAXSPEED)
//Precision is in hours. 1 is default
var finalChart=[{y:en_chartData[rank][en_chartData[rank].length-1].points,x:en_chartData[rank][en_chartData[rank].length-1].date}]
//Start from the time of the last reported rank.
var myPoints = startPoint.points
var pointSpeed = Math.ceil(GetRank(rank,en)/(moment(startPoint.date).diff(EVENTSTART_en,'minutes')/60))
var speedGoal = MAXSPEED*nyoomfactor[rank]
while (startTime<EVENTEND_en) {
startTime.add(precision,'hours')
myPoints+=Math.floor(pointSpeed)
if (EVENTEND_en.diff(startTime,'hours')>11) {
pointSpeed-=pointSpeed*(slowdownFactor[rank]*10/*CONSTANT for adjustment*/)
} else {
pointSpeed=Math.max(
GetRank(rank,en)/(moment(startPoint.date).diff(EVENTSTART_en,'minutes')/60),
Math.min((12-EVENTEND_en.diff(startTime,'hours'))*(speedGoal/5),speedGoal))
//pointSpeed+=(speedGoal-pointSpeed) //Increase towards final goal.
//console.log(pointSpeed)
}
finalChart=[...finalChart,{y:Number.isInteger(myPoints)?myPoints:"???",x:moment(startTime)}]
}
predictionen_chartData[rank]=finalChart
return finalChart
} else
if (PREDICTIONS_en&&startTime.diff(EVENTSTART_en,'hours')>24&&moment(startPoint.date).diff(EVENTSTART_en,'hours')>=24) {
//console.log(MAXSPEED)
//Precision is in hours. 1 is default
var finalChart=[{y:en_chartData[rank][en_chartData[rank].length-1].points,x:en_chartData[rank][en_chartData[rank].length-1].date}]
//Start from the time of the last reported rank.
var myPoints = startPoint.points
var pointSpeed = GetRate(rank,en)
var speedGoal = MAXSPEED*nyoomfactor[rank]
while (startTime<EVENTEND_en) {
startTime.add(precision,'hours')
myPoints+=Math.floor(pointSpeed)
if (EVENTEND_en.diff(startTime,'hours')>11) {
pointSpeed-=pointSpeed*(slowdownFactor[rank]*10/*CONSTANT for adjustment*/)
} else {
pointSpeed=Math.max(
GetRank(rank,en)/(moment(startPoint.date).diff(EVENTSTART,'minutes')/60),
Math.min((12-EVENTEND_en.diff(startTime,'hours'))*(speedGoal/5),speedGoal))
//pointSpeed+=(speedGoal-pointSpeed) //Increase towards final goal.
//console.log(pointSpeed)
}
finalChart=[...finalChart,{y:Number.isInteger(myPoints)?myPoints:"???",x:moment(startTime)}]
}
en_predictionChartData[rank]=finalChart
return finalChart
} else {
return []
}
} else {
if (!chartData[rank]) { if (!chartData[rank]) {
return [] return []
} }
@ -1424,6 +1640,7 @@ function CreatePrediction(precision,rank) {
} else { } else {
return [] return []
} }
}
} }
function numberWithCommas(x) { function numberWithCommas(x) {
@ -1436,7 +1653,17 @@ function numberWithCommas(x) {
} }
} }
function ChartData(rank) { function ChartData(rank,en) {
if (en) {
if (!en_chartData[rank]) {
return [{x:0,y:0}]
}
if (rank<=20) {
return [...en_chartData[rank].map((data)=>{return {x:data.date,y:data.points}}),{x:moment().isBefore(EVENTEND)?moment():EVENTEND,y:en_chartData[rank][en_chartData[rank].length-1].points}]
} else {
return [{x:EVENTSTART_en,y:0},...en_chartData[rank].map((data)=>{return {x:data.date,y:data.points}})]
}
} else {
if (!chartData[rank]) { if (!chartData[rank]) {
return [{x:0,y:0}] return [{x:0,y:0}]
} }
@ -1445,17 +1672,51 @@ function ChartData(rank) {
} else { } else {
return [{x:EVENTSTART,y:0},...chartData[rank].map((data)=>{return {x:data.date,y:data.points}})] return [{x:EVENTSTART,y:0},...chartData[rank].map((data)=>{return {x:data.date,y:data.points}})]
} }
}
} }
function GetRank(rank) { function GetRank(rank,en) {
if (en) {
if (en_chartData[rank]) {
return en_chartData[rank][en_chartData[rank].length-1].points
} else {
return "???"
}
} else {
if (chartData[rank]) { if (chartData[rank]) {
return chartData[rank][chartData[rank].length-1].points return chartData[rank][chartData[rank].length-1].points
} else { } else {
return "???" return "???"
} }
}
} }
function GetEstimate(rank) { function GetEstimate(rank,en) {
if (en) {
if (en_predictionChartData[rank]) {
var currentEstimate = 0
if (rank>20 && moment().diff(moment(en_chartData[rank][en_chartData[rank].length-1].date),'hours')>0.5) {
for (var i=en_predictionChartData[rank].length-1;i>=0;i--) {
if (moment(en_predictionChartData[rank][i].x).isAfter(moment())) {
currentEstimate=en_predictionChartData[rank][i].y
} else {
break;
}
}
return currentEstimate
} else {
if (rank>20) {
return GetRank(rank,en)
} else {
return "---"
}
}
} else {
return "???"
}
} else {
if (predictionChartData[rank]) { if (predictionChartData[rank]) {
var currentEstimate = 0 var currentEstimate = 0
if (rank>20 && moment().diff(moment(chartData[rank][chartData[rank].length-1].date),'hours')>0.5) { if (rank>20 && moment().diff(moment(chartData[rank][chartData[rank].length-1].date),'hours')>0.5) {
@ -1478,32 +1739,50 @@ function GetEstimate(rank) {
} else { } else {
return "???" return "???"
} }
}
} }
function GetTime(rank) { function GetTime(rank,en) {
if (en) {
if (en_chartData[rank]) {
return moment(en_chartData[rank][en_chartData[rank].length-1].date).fromNow()
} else {
return ""
}
} else {
if (chartData[rank]) { if (chartData[rank]) {
return moment(chartData[rank][chartData[rank].length-1].date).fromNow() return moment(chartData[rank][chartData[rank].length-1].date).fromNow()
} else { } else {
return "" return ""
} }
}
} }
function GetUpdateColor(rank) { function GetUpdateColor(rank,en) {
if (en) {
if (en_chartData[rank]) {
return "rgba(255,"+Math.max(255-moment().diff(moment(en_chartData[rank][en_chartData[rank].length-1].date),'hours')*3,0)+","+Math.max(255-moment().diff(moment(en_chartData[rank][en_chartData[rank].length-1].date),'hours')*3,0)+",1)"
} else {
return ""
}
} else {
if (chartData[rank]) { if (chartData[rank]) {
return "rgba(255,"+Math.max(255-moment().diff(moment(chartData[rank][chartData[rank].length-1].date),'hours')*3,0)+","+Math.max(255-moment().diff(moment(chartData[rank][chartData[rank].length-1].date),'hours')*3,0)+",1)" return "rgba(255,"+Math.max(255-moment().diff(moment(chartData[rank][chartData[rank].length-1].date),'hours')*3,0)+","+Math.max(255-moment().diff(moment(chartData[rank][chartData[rank].length-1].date),'hours')*3,0)+",1)"
} else { } else {
return "" return ""
} }
}
} }
var tableValues={} var tableValues={}
var en_tableValues={}
app.get('/eventdata',function(req,res){ app.get('/eventdata',function(req,res){
var eventinfo = [] var eventinfo = []
db.query('select * from event order by id desc limit 1') db.query('select * from '+(req.query.en?"en_":"")+'event order by id desc limit 1')
.then((data)=>{ .then((data)=>{
eventinfo = data.rows; eventinfo = data.rows;
if (!req.query.event) { if (!req.query.event) {
return db.query('select distinct on (rank) rank,eventid,date,name,description,points from eventdata where eventid=$1 order by rank,date desc',[moment(eventinfo[0].startdate).isBefore(moment())?eventinfo[0].eventid:eventinfo[0].eventid-1]) return db.query('select distinct on (rank) rank,eventid,date,name,description,points,difference from (select lead(points) over (partition by rank order by rank,date desc)-points difference,* from '+(req.query.en?"en_":"")+'eventdata where eventid=$1 order by rank,date desc)t order by rank,date desc;',[moment(eventinfo[0].startdate).isBefore(moment())?eventinfo[0].eventid:eventinfo[0].eventid-1])
} else { } else {
} }
@ -1533,10 +1812,87 @@ app.get('/eventdata',function(req,res){
}) })
}) })
var rankings = {
1:"Maho",
2:"Shinobu",
3:"Muni",
4:"Rei",
5:"Yuka",
6:"Kyoko",
7:"Esoran",
8:"Rinku",
9:"Ibuki",
10:"Esora",
11:"Noa",
12:"Saki",
13:"Towa",
14:"Rika",
15:"Aoi",
16:"Kurumi",
17:"Saori",
18:"Hiiro",
19:"Michiru",
20:"Tsubaki"
}
var lastRankingUpdate=moment()
var notPlaying=[
"Dalia","Marika","Nyochio","Nagisa","Miyu","Haruna","Miiko","Airi","Mana","Shano","Touka"
]
function RunRankingUpdate() {
if (moment().diff(lastRankingUpdate,'minutes')>=1) {
for (var i=0;i<20;i++) {
//Possibility to switch two positions.
var swap=false
if (i==0) {
if (Math.random()<=0.01) {
swap=true;
}
} else
if (Math.random()<=0.05){
swap=true;
}
if (swap) {
if (i<19) {
var previousName=rankings[i+1]
var newName=rankings[i+2]
rankings[i+1]=newName
rankings[i+2]=previousName
} else {
//Bring in a new name, swap out the old.
var previousName=rankings[i+1]
var newRandomSlot=Math.floor(Math.random()*notPlaying.length)
var newName=notPlaying[newRandomSlot]
rankings[i+1]=newName
notPlaying[newRandomSlot]=previousName
}
}
}
lastRankingUpdate=moment()
}
}
app.get('/eventdata/t50',function(req,res){
var eventinfo = []
db.query('select * from '+(req.query.en?"en_":"")+'event order by id desc limit 1')
.then((data)=>{
eventinfo = data.rows;
return db.query('select distinct on (rank) rank,eventid,date,name,description,points,difference from (select lead(points) over (partition by rank order by rank,date desc)-points difference,* from '+(req.query.en?"en_":"")+'eventdata where rank>20 and eventid=$1 order by rank,date desc)t order by rank,date desc;',[moment(eventinfo[0].rank_end).isBefore(moment())?eventinfo[0].eventid:eventinfo[0].eventid-1])
})
.then((data)=>{
return res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
})
app.get('/eventdata/t20',function(req,res){ app.get('/eventdata/t20',function(req,res){
var eventinfo = [] var eventinfo = []
if (req.query.date&&req.query.rank) { if (req.query.date&&req.query.rank) {
db.query('select * from eventdata where date<=$1 and rank=$2 and eventid=$3 order by date desc limit 1;',[req.query.date,req.query.rank,10]) db.query('select * from '+(req.query.en?"en_":"")+'eventdata where date<=$1 and rank=$2 and eventid=$3 order by date desc limit 1;',[req.query.date,req.query.rank,req.query.eventid])
.then((data)=>{ .then((data)=>{
res.status(200).json(data.rows) res.status(200).json(data.rows)
}) })
@ -1545,7 +1901,7 @@ app.get('/eventdata/t20',function(req,res){
}) })
} else } else
if (req.query.luminous) { if (req.query.luminous) {
db.query("select * from eventdata where (date>='2021-02-17 23:36:16.383+00' and date<'2021-02-19 15:35:16.716+00' and rank=12) or (date>='2021-02-19 15:35:16.716+00' and rank=11) and eventid=10 order by id asc;") db.query("select * from "+(req.query.en?"en_":"")+"eventdata where (date>='2021-02-17 23:36:16.383+00' and date<'2021-02-19 15:35:16.716+00' and rank=12) or (date>='2021-02-19 15:35:16.716+00' and rank=11) and eventid=10 order by id asc;")
.then((data)=>{ .then((data)=>{
res.status(200).json(data.rows) res.status(200).json(data.rows)
}) })
@ -1554,7 +1910,7 @@ app.get('/eventdata/t20',function(req,res){
}) })
} else } else
if (req.query.all&&req.query.event) { if (req.query.all&&req.query.event) {
db.query('select * from eventdata where eventid=$1 order by date asc;',[req.query.event]) db.query('select * from (select lag(points) over (partition by rank order by date asc)-points difference,rank,eventid,date,name,points from '+(req.query.en?"en_":"")+'eventdata where eventid=$1 order by date asc)t',[req.query.event])
.then((data)=>{ .then((data)=>{
res.status(200).json(data.rows) res.status(200).json(data.rows)
}) })
@ -1563,7 +1919,7 @@ app.get('/eventdata/t20',function(req,res){
}) })
} else } else
if (req.query.tier&&req.query.event) { if (req.query.tier&&req.query.event) {
db.query('select * from eventdata where eventid=$1 and rank=$2 order by date desc',[req.query.event,req.query.tier]) db.query('select * from (select lag(points) over (partition by rank order by date asc)-points difference,rank,eventid,date,name,points from '+(req.query.en?"en_":"")+'eventdata where eventid=$1 and rank=$2 order by date desc)t',[req.query.event,req.query.tier])
.then((data)=>{ .then((data)=>{
res.status(200).json(data.rows) res.status(200).json(data.rows)
}) })
@ -1572,58 +1928,131 @@ app.get('/eventdata/t20',function(req,res){
}) })
} else } else
if (req.query.chart){ if (req.query.chart){
function RandomQuestion() {
var value = Math.random()
if (value<=0.7) {
return "???"
} else
if (value<=0.9) {
return "Miyu"
} else
if (value<=0.95) {
return "Muni"
} else {
return "MuniMuni"
}
}
if (req.query.event||moment().diff(lastCachedDate,'minutes')>=1||(req.query.force&&moment().diff(lastCachedDate,'seconds')>=10)) { if (req.query.event||moment().diff(lastCachedDate,'minutes')>=1||(req.query.force&&moment().diff(lastCachedDate,'seconds')>=10)) {
chartData={} chartData={}
predictionChartData={} predictionChartData={}
diffData=[] diffData=[]
db.query('select * from event order by id desc limit 1') db.query('select * from '+(req.query.en?"en_":"")+'event order by id desc limit 1')
.then((data)=>{ .then((data)=>{
eventinfo = data.rows; eventinfo = data.rows;
return db.query('select * from eventdata where eventid=$1 order by date asc',[(req.query.event)?req.query.event:eventinfo[0].eventid]) return db.query('select * from (select lag(points) over (partition by rank order by date asc)-points difference,rank,eventid,date,name,points from '+(req.query.en?"en_":"")+'eventdata where eventid=$1 order by date asc)t',[(req.query.event)?req.query.event:moment(eventinfo[0].rank_end).isBefore(moment())?eventinfo[0].eventid:eventinfo[0].eventid-1])
}) })
.then((data)=>{ .then((data)=>{
if (data&&data.rows&&data.rows.length>0) { if (data&&data.rows&&data.rows.length>0) {
data.rows.map((obj)=>{if (chartData[obj.rank]) {chartData[obj.rank]=[...chartData[obj.rank],obj]} else {chartData[obj.rank]=[obj]}}) data.rows.map((obj)=>{
if (req.query.en) {
if (en_chartData[obj.rank]) {en_chartData[obj.rank]=[...en_chartData[obj.rank],obj]} else {en_chartData[obj.rank]=[obj]}
} else {
if (chartData[obj.rank]) {chartData[obj.rank]=[...chartData[obj.rank],obj]} else {chartData[obj.rank]=[obj]}
}
})
SetupPredictionModel() SetupPredictionModel()
var tiers= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,50,100,500,1000,2000,5000,10000,20000,30000,50000] var tiers= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,50,100,500,1000,2000,5000,10000,20000,30000,50000]
if (req.query.en) {
for (t of tiers) {
CreatePrediction(1,t,req.query.en)
var est = GetEstimate(t,req.query.en)
var temprate = 0
if (en_chartData[t]) {
temprate=(t<=20)?(en_chartData[t])?Math.ceil(GetRate(t,req.query.en)):undefined:Math.ceil(GetRank(t,req.query.en)/(moment(en_chartData[t][en_chartData[t].length-1].date).diff(EVENTSTART_en,'minutes')/60))
}
var tempname="";
if (en_chartData[t]&&en_chartData[t][en_chartData[t].length-1]&&en_chartData[t][en_chartData[t].length-1].name) {
tempname=en_chartData[t][en_chartData[t].length-1].name
}
var tempdesc="";
if (en_chartData[t]&&en_chartData[t][en_chartData[t].length-1]&&en_chartData[t][en_chartData[t].length-1].description) {
tempdesc=en_chartData[t][en_chartData[t].length-1].description
}
en_tableValues[t]={
points:GetRank(t,req.query.en),
lastUpdate:GetTime(t,req.query.en),
lastUpdateColor:GetUpdateColor(t,req.query.en),
rate:temprate?temprate:0,
count:GetPointCount(t,req.query.en),
name:tempname,
description:tempdesc,
estimate:Number.isInteger(est)?Math.ceil(est):est,
prediction:(en_predictionChartData[t]&&moment().isBefore(EVENTEND_en))?en_predictionChartData[t][en_predictionChartData[t].length-1].y:RandomQuestion()
}
}
lastCachedDate=moment()
res.status(200).send({predictionData:en_predictionChartData,statistics:tableValues})
} else {
for (t of tiers) { for (t of tiers) {
CreatePrediction(1,t) CreatePrediction(1,t,req.query.en)
var est = GetEstimate(t) var est = GetEstimate(t,req.query.en)
var temprate = 0 var temprate = 0
if (chartData[t]) { if (chartData[t]) {
temprate=(t<=20)?(chartData[t])?Math.ceil(GetRate(t)):undefined:Math.ceil(GetRank(t)/(moment(chartData[t][chartData[t].length-1].date).diff(EVENTSTART,'minutes')/60)) temprate=(t<=20)?(chartData[t])?Math.ceil(GetRate(t)):undefined:Math.ceil(GetRank(t)/(moment(chartData[t][chartData[t].length-1].date).diff(EVENTSTART,'minutes')/60))
} }
var tempname="";
if (chartData[t]&&chartData[t][chartData[t].length-1]&&chartData[t][chartData[t].length-1].name) {
tempname=chartData[t][chartData[t].length-1].name
}
var tempdesc="";
if (chartData[t]&&chartData[t][chartData[t].length-1]&&chartData[t][chartData[t].length-1].description) {
tempdesc=chartData[t][chartData[t].length-1].description
}
tableValues[t]={ tableValues[t]={
points:GetRank(t), points:GetRank(t),
lastUpdate:GetTime(t), lastUpdate:GetTime(t),
lastUpdateColor:GetUpdateColor(t), lastUpdateColor:GetUpdateColor(t),
rate:temprate?temprate:0, rate:temprate?temprate:0,
count:GetPointCount(t), count:GetPointCount(t),
name:tempname,
description:tempdesc,
estimate:Number.isInteger(est)?Math.ceil(est):est, estimate:Number.isInteger(est)?Math.ceil(est):est,
prediction:(predictionChartData[t])?predictionChartData[t][predictionChartData[t].length-1].y:"???" prediction:(predictionChartData[t]&&moment().isBefore(EVENTEND))?predictionChartData[t][predictionChartData[t].length-1].y:RandomQuestion()
} }
} }
lastCachedDate=moment() lastCachedDate=moment()
res.status(200).send({predictionData:predictionChartData,statistics:tableValues}) res.status(200).send({predictionData:predictionChartData,statistics:tableValues})
}
} else {
if (req.query.en) {
res.status(200).send({predictionData:en_predictionChartData,statistics:en_tableValues})
} else { } else {
res.status(200).send({predictionData:predictionChartData,statistics:tableValues}) res.status(200).send({predictionData:predictionChartData,statistics:tableValues})
} }
}
}) })
.catch((err)=>{ .catch((err)=>{
res.status(500).send(err.message) res.status(500).send(err.message)
}) })
} else {
if (req.query.en) {
res.status(200).send({predictionData:en_predictionChartData,statistics:en_tableValues})
} else { } else {
res.status(200).send({predictionData:predictionChartData,statistics:tableValues}) res.status(200).send({predictionData:predictionChartData,statistics:tableValues})
} }
}
} else { } else {
db.query('select * from event order by id desc limit 1') db.query('select * from event order by id desc limit 1')
.then((data)=>{ .then((data)=>{
eventinfo = data.rows; eventinfo = data.rows;
return db.query('select distinct on (rank) rank,eventid,date,name,description,points from eventdata where rank<=20 and eventid=$1 order by rank,date desc',[moment(eventinfo[0].startdate).isBefore(moment())?eventinfo[0].eventid:eventinfo[0].eventid-1]) return db.query('select distinct on (rank) rank,eventid,date,name,description,points,difference from (select lead(points) over (partition by rank order by rank,date desc)-points difference,* from '+(req.query.en?"en_":"")+'eventdata where rank<=20 and eventid=$1 order by rank,date desc)t order by rank,date desc;',[moment(eventinfo[0].rank_end).isBefore(moment())?eventinfo[0].eventid:eventinfo[0].eventid-1])
}) })
.then((data)=>{ .then((data)=>{
var finaldata = data.rows var finaldata = data.rows
var tiers= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] var tiers= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
//RunRankingUpdate()
for (t of tiers) { for (t of tiers) {
//console.log(t) //console.log(t)
//if (finaldata[String(t)]===undefined) {finaldata[String(t)]={"rank":t,"eventid":eventinfo[0].eventid,"name":"","description":"","date":eventinfo[0].startdate,"points":0}} //if (finaldata[String(t)]===undefined) {finaldata[String(t)]={"rank":t,"eventid":eventinfo[0].eventid,"name":"","description":"","date":eventinfo[0].startdate,"points":0}}
@ -1638,6 +2067,10 @@ app.get('/eventdata/t20',function(req,res){
} else { } else {
finaldata[i].rate=temprate finaldata[i].rate=temprate
} }
//finaldata[i].name="Muni";
/*if (rankings[t]) {
finaldata[i].name=rankings[t]
}*/
break; break;
} }
} }
@ -1645,7 +2078,11 @@ app.get('/eventdata/t20',function(req,res){
finaldata=[...finaldata,{"rate":0,"rank":t,"eventid":eventinfo[0].eventid,"name":"","description":"","date":eventinfo[0].startdate,"points":0}] finaldata=[...finaldata,{"rate":0,"rank":t,"eventid":eventinfo[0].eventid,"name":"","description":"","date":eventinfo[0].startdate,"points":0}]
} }
} }
if (req.query.maxspeed) {
res.status(200).json([...finaldata,{maxspeed:MAXSPEED}])
} else {
res.status(200).json(finaldata) res.status(200).json(finaldata)
}
}) })
.catch((err)=>{ .catch((err)=>{
res.status(500).send(err.message) res.status(500).send(err.message)
@ -1653,6 +2090,33 @@ app.get('/eventdata/t20',function(req,res){
} }
}) })
app.get('/cans',function(req,res){
db.query('select (select count(*) from cans where can=true) as cans,(select count(*) from cans where can=false) as notcan;')
.then((data)=>{res.status(200).send(data.rows[0])})
.catch((err)=>{res.status(500).send(err.message)})
})
app.get('/ev',function(req,res){
if (req.query.all) {
db.query('select * from '+(req.query.en?"en_":"")+'event order by id desc;')
.then((data)=>{res.status(200).send(data.rows)})
.catch((err)=>{res.status(500).send(err.message)})
} else {
db.query('select * from '+(req.query.en?"en_":"")+'event order by id desc limit 1;')
.then((data)=>{res.status(200).send(data.rows[0])})
.catch((err)=>{res.status(500).send(err.message)})
}
})
app.post('/cans',function(req,res){
if (req.body&&(req.body.cans!==undefined&&req.body.cans!==null)) {
db.query('insert into cans(date,can) values($1,$2)',[moment(),req.body.cans])
.then((data)=>{res.status(200).send("Done!")})
} else {
res.status(400).send("Invalid credentials!")
}
})
app.post('/streamkill/:id',function (req,res){ app.post('/streamkill/:id',function (req,res){
if (req.body&&req.body.username&&req.body.authentication_token) { if (req.body&&req.body.username&&req.body.authentication_token) {
GetUserLoginAllowed(req.body.username.trim(),req.body.authentication_token.trim()) GetUserLoginAllowed(req.body.username.trim(),req.body.authentication_token.trim())

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save