edit-task
Home
Up
Delete
Task Name:
Task Description:
#### - UPDATE - PAGE rankings - use REQUEST to pull data from external rankings api, TRY rankings module
TaskGroup ID:
Start Date:
Start Time:
Duration:
Priority:
Status:
To Do
Completed
In Process
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">4800-v-004-002</h1> <h2>[previously]</h2> <ol> <li><strong>[2015-06-09] NEW task IN PAGE rankings</strong></li> <ol> <li>x] # # - UPDATE rankings - use REQUEST to pull data from api - i] revisiting pulling the drivers data FROM src=sospep.people using api call, ] see TRY 1, TRY 2, TRY 3 and TRY 4 ] SUCCESS with TRY 4 using the 'request' package, see example code in homes.js-v-001</li> </ol> <li><strong>[2015-06-10] NEW task IN PAGE</strong></li> <ol> <li>] # # - CREATE-module - getEntrants - put code for pulling entrants data, then processing it, into a seperate module(VS in index 'controller)</li> </ol></ol> <h2>[currently]</h2> <ol> <li><strong>[2015-06-10] NEW task IN</strong></li> <ol> <li><strong>] # # - request api -</strong> lets get that request working properly, http.get request</li> <li>*] TRY 1 - SRC = SO ? <a href="http://stackoverflow.com/questions/9577611/http-get-request-in-node-js-express" target="_blank">http://stackoverflow.com/questions/9577611/http-get-request-in-node-js-express</a> response # 2</li> <li>*] uses = http</li> <li>] SUCCESS - try# 4 </li> </ol> <li><strong>[00:00] NEW task IN </strong></li> <ol> <li><strong>] # # - data</strong> </li> <li><span style="color: #4f76ac;">] var</span> url <span style="color: #1e7c70;">=</span> <span style="color: #823125;">'http://sospep.com/qry/Select-IndividualsInMemberGroup-a/25'</span><span style="color: #1e7c70;">;</span> //returns nascar drivers list</li> <li>] { race: '2015-13', id: 107, nameDriver: 'Ricky Stenhouse Jr', teamID: '17', points: 0, top10s: 'one', description: 'ricky is awesome' },</li> </ol> <li><strong>* [00:00] NEW task IN </strong></li> <ol> <li><strong>] # # - use existing 'drivers' to create an 'entrants list' </strong></li> <li>] person - HAS id, name</li> <li>] request json - all</li> <li>] iterate 'records' and add desired properties to each driver record NEED ADD - ] race, ] teamID, ] points ] top10(CALC)</li> <li>] PRB teamID - create/use lookupDriver function</li> <li>] save as file</li> <li>] pull data for view from file</li> <li>] admin command to /get-entrants</li> </ol> <li><strong>[00:00] NEW task IN sospep/membergroup/ {nations/nascar/drivers} </strong></li> <ol> <li>x] # # - data - drivers</li> <li>x] changed person.status of non active drivers(7) to 'asked' from default of ask, USE this param to pull just the drivers entered in a given race</li> </ol> <li><strong>[00:00] NEW task IN sospep app</strong></li> <ol> <li>x] # # - app sospep - make new dir x] api</li> </ol> <li><strong>[00:00] NEW task IN sospep app pages </strong></li> <ol> <li>x] # # - sospep - NEW endpoint - raceEntrants</li> <li>x] = ( copy SelectIndividualsInMemberGroup-a /{membergroup id} /{status} </li> <ol> <li>] COMPARE MemberGroup-a - concats first and last to return fullname</li> <li>] VS MemberGroup - returns first and last name</li> <li>]</li> </ol> <li>] ?? == current session</li> <li>*] this gets me a 'pseudo list' of entrants for the current race *, still NEED the actual list of entrants ..</li> </ol> <li><strong>> [00:00] NEW task IN </strong></li> <ol> <li>] # # - actual entrants - COMPARE</li> </ol> <li><strong>> [00:00] NEW task IN PASS - rankings</strong></li> <ol> <li>x] # # - get entrants (aka drivers) for current race - x] call new api,</li> </ol> <li><strong>> [00:00] NEW task IN PASS - rankings</strong></li> <ol> <li>] # # - TRY CREATE module for 'getEntrants' code</li> <li>] var entrants = [</li> <li>];</li> <li>module.exports(getEntrants)</li> <li>] iterate the list of drivers to ADD additional properties</li> </ol> <li><strong>[00:00] NEW task IN </strong></li> <ol> <li>] # # - CREATE module - take logic for building entrants list, move into module</li> <li>] using <strong>module.exports = function(){}</strong> then ADD route VS</li> <li>] using <strong>var myModule = { properties:'values'}</strong> module.exports(myModule) then ADD route</li> </ol> <li><strong>[00:00] NEW task IN NOTE</strong></li> <ol> <li>] entrants.js - v-001 = first example, see 10.3, 500 error</li> <li>] entrants.js -v-002 = simple example of passing data</li> <li>*] PAGE (ex index) requires var entrants = requries entrants.js, CANT invoke</li> </ol> <li><strong>[00:00] NEW task IN NOTE its WORKING (it may NOT be right, but it is working)</strong></li> <ol> <li>] filename.js - using module.exports, ex entrants.js</li> <li>] include pseudo path to .js file in app.js routes section, example = <span style="color: #af6326; font-weight: bold;">require</span><span style="color: #1e7c70;">(</span><span style="color: #823125;">'./routes/entrants'</span><span style="color: #1e7c70;">)(</span>app<span style="color: #1e7c70;">);</span></li> <li>] define var in file using - ex index - var drivers = require('./filename')</li> <li>] call var function where you need entrants()</li> <li>CC] # # - understanding expressjs - ]</li> </ol> <li><strong>[2015-06-11] DONE</strong><ol> <li>] teams table, manually loaded data</li> <li>] lookup function, lookup teamID by driverID, </li> <ol> <li>] fails on loop,</li> <li>] seems to work on invidual</li> </ol> <li>] sospep data - add prop 'priority' to race entrants, USE for teamID</li> <li>] adjust getEntrants api endpoint to return property</li> </ol></li> <li><strong>] DO</strong></li> <ol> <li>] driver (description w/{}, )</li> <li>] rankRace15</li> <li>]- avgfinish-last10 races</li> <li>>] ]</li> </ol> <li>]</li> </ol> <h2>[next]</h2> <ol> <li><strong>] </strong></li> </ol> <p> </p> <hr /> <pre style="background: white; color: black; font-family: Consolas; font-size: 10pt;"><strong>TRY 1 </strong></pre> <pre style="background: white; color: black; font-family: Consolas; font-size: 10pt;"> <span style="color: #4f76ac;">var</span> http <span style="color: #1e7c70;">=</span> <span style="color: #af6326; font-weight: bold;">require</span><span style="color: #1e7c70;">(</span><span style="color: #823125;">'http'</span><span style="color: #1e7c70;">);</span> <span style="color: #4f76ac;">var</span> options <span style="color: #1e7c70;">=</span> <span style="color: #1e7c70;">{</span> host<span style="color: #1e7c70;">:</span> <span style="color: #823125;">'sospep.com'</span><span style="color: #1e7c70;">,</span> path<span style="color: #1e7c70;">:</span> <span style="color: #823125;">'/qry/Select-IndividualsInMemberGroup-a/25'</span> <span style="color: #1e7c70;">};</span> <span style="color: #4f76ac;">var</span> reqDrivers <span style="color: #1e7c70;">=</span> http.get<span style="color: #1e7c70;">(</span>url<span style="color: #1e7c70;">,</span> <span style="color: #4f76ac;">function</span> <span style="color: #1e7c70;">(</span>res1<span style="color: #1e7c70;">)</span> <span style="color: #1e7c70;">{</span> console.log<span style="color: #1e7c70;">(</span><span style="color: #823125;">'STATUS: '</span> <span style="color: #1e7c70;">+</span> res1.statusCode<span style="color: #1e7c70;">);</span> console.log<span style="color: #1e7c70;">(</span><span style="color: #823125;">'HEADERS: '</span> <span style="color: #1e7c70;">+</span> <span style="color: #4f76ac;">JSON</span>.stringify<span style="color: #1e7c70;">(</span>res1.headers<span style="color: #1e7c70;">));</span> <span style="color: #46830d;">// Buffer the body entirely for processing as a whole.</span> <span style="color: #4f76ac;">var</span> bodyChunks <span style="color: #1e7c70;">=</span> <span style="color: #1e7c70;">[];</span> res1.on<span style="color: #1e7c70;">(</span><span style="color: #823125;">'data'</span><span style="color: #1e7c70;">,</span> <span style="color: #4f76ac;">function</span> <span style="color: #1e7c70;">(</span>chunk<span style="color: #1e7c70;">)</span> <span style="color: #1e7c70;">{</span> <span style="color: #46830d;">// You can process streamed parts here...</span> bodyChunks.push<span style="color: #1e7c70;">(</span>chunk<span style="color: #1e7c70;">);</span> <span style="color: #1e7c70;">})</span>.on<span style="color: #1e7c70;">(</span><span style="color: #823125;">'end'</span><span style="color: #1e7c70;">,</span> <span style="color: #4f76ac;">function</span> <span style="color: #1e7c70;">()</span> <span style="color: #1e7c70;">{</span> <span style="color: #4f76ac;">var</span> body <span style="color: #1e7c70;">=</span> Buffer.concat<span style="color: #1e7c70;">(</span>bodyChunks<span style="color: #1e7c70;">);</span> <span style="color: #46830d;">// console.log('BODY: ' + body);</span> <span style="color: #46830d;">// ...and/or process the entire body here.</span> <span style="color: #46830d;">// body = JSON.parse(body);</span> <span style="color: #1e7c70;">})</span> <span style="color: #1e7c70;">});</span> reqDrivers.on<span style="color: #1e7c70;">(</span><span style="color: #823125;">'error'</span><span style="color: #1e7c70;">,</span> <span style="color: #4f76ac;">function</span> <span style="color: #1e7c70;">(</span>e<span style="color: #1e7c70;">)</span> <span style="color: #1e7c70;">{</span> console.log<span style="color: #1e7c70;">(</span><span style="color: #823125;">'ERROR: '</span> <span style="color: #1e7c70;">+</span> e.message<span style="color: #1e7c70;">);</span> <span style="color: #1e7c70;">});</span> </pre> <p> </p> <hr /> <p> <strong>TRY 2</strong> <a href="https://docs.nodejitsu.com/articles/HTTP/clients/how-to-create-a-HTTP-request" target="_blank">https://docs.nodejitsu.com/articles/HTTP/clients/how-to-create-a-HTTP-request</a></p> <pre style="background: white; color: black; font-family: Consolas; font-size: 10pt;"><span style="color: #4f76ac;">var</span> scoot <span style="color: #1e7c70;">=</span> <span style="color: #823125;">''</span><span style="color: #1e7c70;">;</span> <span style="color: #4f76ac;">var</span> http <span style="color: #1e7c70;">=</span> <span style="color: #af6326; font-weight: bold;">require</span><span style="color: #1e7c70;">(</span><span style="color: #823125;">'http'</span><span style="color: #1e7c70;">);</span> callback <span style="color: #1e7c70;">=</span> <span style="color: #4f76ac;">function</span> <span style="color: #1e7c70;">(</span>response<span style="color: #1e7c70;">)</span> <span style="color: #1e7c70;">{</span> <span style="color: #4f76ac;">var</span> str <span style="color: #1e7c70;">=</span> <span style="color: #823125;">''</span><span style="color: #1e7c70;">;</span> <span style="color: #46830d;">//another chunk of data has been recieved, so append it to `str`</span> response.on<span style="color: #1e7c70;">(</span><span style="color: #823125;">'data'</span><span style="color: #1e7c70;">,</span> <span style="color: #4f76ac;">function</span> <span style="color: #1e7c70;">(</span>chunk<span style="color: #1e7c70;">)</span> <span style="color: #1e7c70;">{</span> str <span style="color: #1e7c70;">+=</span> chunk<span style="color: #1e7c70;">;</span> <span style="color: #1e7c70;">});</span> <span style="color: #46830d;">//the whole response has been recieved, so we just print it out here</span> response.on<span style="color: #1e7c70;">(</span><span style="color: #823125;">'end'</span><span style="color: #1e7c70;">,</span> <span style="color: #4f76ac;">function</span> <span style="color: #1e7c70;">()</span> <span style="color: #1e7c70;">{</span> console.log<span style="color: #1e7c70;">(</span>str<span style="color: #1e7c70;">);</span> <span style="color: #46830d;">// return JSON.stringify(str);</span> <span style="color: #1e7c70;">});</span> <span style="color: #1e7c70;">}</span> http.request<span style="color: #1e7c70;">(</span>url<span style="color: #1e7c70;">,</span> callback<span style="color: #1e7c70;">)</span>.end<span style="color: #1e7c70;">();</span> <span style="color: #46830d;">// var str = '';</span></pre> <hr /> <p> <strong>TRY 3 - </strong>use previous example code in home.js page,</p> <p>successfully pulled data from api and piped that data to a file on the server</p> <p>using request package, try get vs fs</p> <p><strong>TRY 4</strong> - use tutorial in art# 4566</p> <p>KEY - moving the http request outside of the app.get(){ } function</p> <p> </p> <p> </p> <p> </p> <p> </p>