Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

but howw??? #2

Closed
indefinitelee opened this issue Dec 10, 2016 · 1 comment
Closed

but howw??? #2

indefinitelee opened this issue Dec 10, 2016 · 1 comment

Comments

@indefinitelee
Copy link
Owner

Ok, fetch call to url returns a large object, iterate through with .map to retrieve each of the fields that I want.
services/stats-api.js

function getStats(req, res, next){
  fetch(`fantasy.premierleague.com/drf/bootstrap-static`)
    .then(r => r.json())
    .then((data) => {
      res.rows = data.elements.map((player) => {
        return {
          firstName: player.first_name,
          secondName: player.second_name,
  1. can I create a calculated field like this?
    onPace: parseInt(ppg)*38
  • maybe this isn't even necessary if i use something like this https://www.npmjs.com/package/react-json-table
    but since .map returns an array i'd have to either change the way I filter the object or turn it back into a json, right? or is .map giving me a new array of objects?
  1. ideally in addition to data retrieved from the fetch there would be a column that would allow users to enter their own total value. since the data would appear on the landing page I'm thinking that my fetch call can be directly in my App.jsx instead of services/stats-api.js

  2. What's the State?

  • the user entered column would have to be in State
  • as well as any recalculated fields
  • any field used in the 3ds graph needs to get it's content from the state - iirc.
  1. graphing data
  • the graph should display two lines which would be identical up to the current game week and then diverge based on the user entered final value.
  • figure out formula to make sure divergence only happens at current week, not since beginning of season.
@nialbima
Copy link

nialbima commented Dec 10, 2016

  1. assuming ppg returns a string containing a valid int, i don't see why not? what happened when you tried it?

  2. The fetch call will generally be faster if it's done in the API rather than the front-end. you really don't want to make the program hang while you wait for response.

    • do you know the game schedule? you could import that, and go fetch an hour after every game rather than waiting on users.
    • yeah, probably you'd want to post it to the API for that user when you submitted. maybe a join table for user_players?
    • also yeah, but the calc should only have one independent variable (you can run it straight inside the code rather than pre-calculating it)
    • depends, i think. if you want it to be dynamic, yes. otherwise you could load a static json and load the file into a preset graph, which would work fine.
    • divergence over time would also be interesting. if you saved the user data, you could let them track how wrong they were (and you'd only need to write one set of calculations to be executed on two sets of data, then compared in the graph).
      • so like, this would depend on a saved user model and saved user data, but assuming you're passing those values in correctly it'd be pretty easy to calculate the divergence during API response. returning that value to d3 seems good. like this maybe? apologies for my shitty JS.
calcDivergence = function(player, user_data, time) { 
    #     var gameTime = function (game) { game.date > time }
    #     var getPoints = function (player) { player.points } 
    #     var player_points = SavedGames.filter(gameTime).map(getPoints)
    #      etc.
(player_points/ user_data_points)
}

I don't know if this is helpful! Hard to know without being there/seeing your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants