-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat: Added chart for history per country #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5453dc3
feat: Added non-interactive chart for history per country
jkga 516db55
chore: changed table and donut border
jkga 7e26403
feat: replaced wopr with blessed stream implementation
jkga c572ca6
fix: chnged cols and rows
jkga 2282e85
Merge branch 'dev' of https://github.com/WarenGonzaga/covid19-tracker…
jkga bc23907
fix: add white borders in table and bar graph
jkga 6f0bc9f
fix: extra lines and commented code
jkga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| node_modules | ||
| .now | ||
| .now | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| const | ||
| blessed = require('blessed'), | ||
| pkg = require('../../../package.json'), | ||
| say = require('../../sayings/threads.json'), | ||
| serverUtil = require('./server-util') | ||
| template = require ('./template.js'), | ||
| ts = Date.now(), | ||
| date_ob = new Date(ts), | ||
| date = date_ob.getDate(), | ||
| month = date_ob.getMonth() + 1, | ||
| year = date_ob.getFullYear(), | ||
| currentdate = month + "/" + date + "/" + year, | ||
| space = ' ', | ||
| br = '\n', | ||
| header = '`COVID19-TRACKER-CLI (v'+pkg.version+')`', | ||
| tagline = '*A curl-based command line tracker for Novel Coronavirus or COVID-19 pandemic.*', | ||
| source = 'Source: https://www.worldometers.info/coronavirus/', | ||
| repo = 'Code: https://github.com/warengonzaga/covid19-tracker-cli', | ||
| bmcurl = 'warengonza.ga/coffee4dev', | ||
| twitterhandle = '@warengonzaga', | ||
| twitterhashtag = '#covid19trackercli', | ||
| gcashNum = '+639176462753', | ||
| ansiBMC = '`(Buy Me A Coffee)` '+bmcurl, | ||
| ansiTwitter = twitterhandle+space+twitterhashtag, | ||
| ansiGCash = '(GCash) '+gcashNum; | ||
|
|
||
|
|
||
| // random sayings | ||
| const randomSay = () => { | ||
| let random = Math.floor(Math.random() * say.length); | ||
| return say[random]; | ||
| }; | ||
|
|
||
| const patchBlessed = () => { | ||
| blessed.Program.prototype.listem = function() {} | ||
| process.on = function() {} | ||
| }; | ||
|
|
||
| patchBlessed(); | ||
|
|
||
| exports.historyCountryTracker = (req, res, n, c, tC, d, tD, r, a, cl, cPOM, u, h, chartType, countryInfo) => { | ||
| const name = n, cases = c, todayCases = tC, | ||
| deaths = d, todayDeaths = tD, recovered = r, | ||
| active = a, critical = cl, casesPerOneMillion = cPOM, | ||
| mortalityPercentage = (d/c)*100, recoveredPercentage = (r/c)*100, | ||
| asof = new Date(u), | ||
| dates = Object.keys(h.timeline[chartType]), | ||
| from = dates[0], | ||
| to = dates[dates.length - 1], | ||
| tableFooter = randomSay(), | ||
| defaultfooter = ansiBMC+ansiTwitter+br+br, | ||
| specialfooter = ansiGCash+br+ansiBMC+ansiTwitter+br+br, | ||
| defaultHeader = header+br+tagline, | ||
| footer = (n.toLowerCase() == 'philippines') ? tableFooter+br+specialfooter+br+source+br+repo : tableFooter+br+defaultfooter+br+source+br+repo; | ||
|
|
||
| // load template with data | ||
| // serverUtil.loadTemplate(template, {jsonData}, callback) | ||
| serverUtil.loadTemplate(template, { | ||
| name, | ||
| cases, | ||
| deaths, | ||
| recovered, | ||
| active, | ||
| casesPerOneMillion, | ||
| todayCases, | ||
| todayDeaths, | ||
| critical, | ||
| mortalityPercentage, | ||
| recoveredPercentage, | ||
| countryInfo, | ||
| from, | ||
| to, | ||
| currentdate, | ||
| asof, | ||
| h, | ||
| defaultHeader, | ||
| footer, | ||
| }, (screen) => { | ||
| res.send(screen+'\r\n'+'\033[?25h') | ||
| }) | ||
|
|
||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** Modified script from blessed-contrib server-util */ | ||
| const blessed = require('blessed'), | ||
| contrib = require('blessed-contrib'), | ||
| Stream = require('stream'); | ||
|
|
||
| function OutputBuffer(options) { | ||
| this.isTTY = true; | ||
| this.columns = options.cols; | ||
| this.rows = options.rows; | ||
| this.write = function(s) { | ||
| s = s.replace('\x1b8', ''); | ||
| options.stream.write(s) | ||
| }; | ||
| this.on = function() {}; | ||
| } | ||
|
|
||
| function InputBuffer() { | ||
| this.isTTY = true; | ||
| this.isRaw = true; | ||
| this.emit = function() {}; | ||
| this.setRawMode = function() {}; | ||
| this.resume = function() {}; | ||
| this.pause = function() {}; | ||
| this.on = function() {}; | ||
| } | ||
|
|
||
ianvizarra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| createScreen = (opt = {}) => { | ||
| const output = new OutputBuffer({stream: opt.stream, cols: 250, rows: 50}); | ||
| const input = new InputBuffer(); //required to run under forever since it replaces stdin to non-tty | ||
| const program = blessed.program({output: output, input: input}); | ||
|
|
||
| let screen = blessed.screen({program: program}); | ||
| return screen | ||
| } | ||
|
|
||
| loadTemplate = (gridTemplateClass, json, callback) => { | ||
|
|
||
| blessed.Screen.global = null | ||
| blessed.Program.global = null | ||
|
|
||
| const | ||
| customStream = new Stream.Transform() | ||
| screen = createScreen({stream: customStream}), | ||
| grid = new contrib.grid({rows: 12, cols: 14, screen: screen}); | ||
|
|
||
| let result = [] | ||
|
|
||
| if(!gridTemplateClass) throw new Error('No template loaded') | ||
|
|
||
| // parse template | ||
| gridTemplateClass.load(grid, json) | ||
|
|
||
| customStream._transform = function (chunk,encoding,done) { | ||
| result.push(chunk.toString()) | ||
| done() | ||
| } | ||
|
|
||
| customStream._final = () => { | ||
| callback(result.join('')) | ||
| } | ||
|
|
||
| customStream.on('error', (e) => { | ||
| // do nothing here | ||
| }) | ||
|
|
||
| screen.render() | ||
|
|
||
| setTimeout(() => { | ||
| customStream.end() | ||
| }, 1000) | ||
| } | ||
|
|
||
| module.exports = { | ||
| createScreen, | ||
| loadTemplate, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| const | ||
| contrib = require('blessed-contrib'), | ||
| chalk = require('chalk'); | ||
|
|
||
| exports.load = (grid, data) => { | ||
|
|
||
| let markdown = grid.set(0, 0, 2, 2, contrib.markdown,{ | ||
| style: { | ||
| border: { | ||
| fg: 'black' | ||
| } | ||
| } | ||
| }) | ||
| markdown.setMarkdown(data.defaultHeader) | ||
|
|
||
| let table = grid.set(0, 2, 2, 7, contrib.table, | ||
| { keys: true | ||
| , fg: 'white' | ||
| , selectedFg: 'white' | ||
| , selectedBg: 'blue' | ||
| , interactive: false | ||
| , label: 'Historical data as of '+data.asof.toLocaleString()+' [Date:'+data.currentdate+']' | ||
| , width: '30%' | ||
| , height: '30%' | ||
| , border: {type: "line", fg: "cyan"} | ||
| , columnSpacing: 10 //in chars | ||
| , columnWidth: [1,16, 12, 12, 12, 18], | ||
| style: { | ||
| border: { | ||
| fg: 'white' | ||
| } | ||
| }}) | ||
|
|
||
| table.setData( | ||
| { headers: ['','Cases', 'Deaths', 'Recovered', 'Active', 'Cases/Million'] | ||
| , data: | ||
| [ | ||
| ['',data.cases, data.deaths, data.recovered, data.active, data.casesPerOneMillion], | ||
| ['','Today Cases', 'Today Deaths', 'Critical', 'Mortality %', 'Recovery %'], | ||
| ['',data.todayCases, data.todayDeaths, data.critical, data.mortalityPercentage, data.recoveredPercentage] | ||
| ] | ||
| }) | ||
|
|
||
| let map = grid.set(2, 0, 3, 4, contrib.map,{ | ||
| style: { | ||
| border: { | ||
| fg: 'black' | ||
| }, | ||
| shapeColor: 'yellow' | ||
| }, | ||
| }) | ||
|
|
||
| map.addMarker({"lon" : data.countryInfo.long, "lat" : data.countryInfo.lat, color: 'magenta', char: '\u24E7'+` ${data.name}`}) | ||
|
|
||
| let bar = grid.set(2, 4, 3, 3, contrib.bar,{ | ||
| barBgColor: 'red', | ||
| barWidth: 7, | ||
| barSpacing: 5, | ||
| xOffset: 3, | ||
| maxHeight: 9, | ||
| style: { | ||
| border: { | ||
| fg: 'white' | ||
| } | ||
| }}) | ||
|
|
||
| screen.append(bar) //must append before setting data | ||
| bar.setData({ titles: ['Cases', 'Deaths', 'Recovered', 'Active'], data: [data.cases, data.deaths, data.recovered, data.active]}) | ||
|
|
||
jkga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let donut = grid.set(2, 7, 3, 2, contrib.donut,{ | ||
| label: 'Mortality Rate', | ||
| radius: 8, | ||
| arcWidth: 3, | ||
| remainColor: 'black', | ||
| yPadding: 2, | ||
| style: { | ||
| border: { | ||
| fg: 'red' | ||
| } | ||
| }, | ||
| data: [ | ||
| {percent: data.mortalityPercentage, label: 'Mortality', color: 'red'}, | ||
| {percent: data.recoveredPercentage, label: 'Recovery', color: 'green'} | ||
| ] | ||
| }); | ||
|
|
||
| let line = grid.set(5, 0, 4, 9, contrib.line, | ||
| { style: | ||
| { line: "yellow" | ||
| , text: "green" | ||
| , baseline: "black", | ||
| border: { | ||
| fg: 'black' | ||
| } | ||
| } | ||
| , xLabelPadding: 3 | ||
| , xPadding: 5 | ||
| , showLegend: true | ||
| , wholeNumbersOnly: true //true=do not show fraction in y axis | ||
| , label: `Cases from ${data.from} to ${data.to}`}) | ||
|
|
||
| let series1 = { | ||
| title: 'Cases', | ||
| x: Object.keys(data.h.timeline.cases), | ||
| y: Object.values(data.h.timeline.cases), | ||
| style: { | ||
| line: 'blue' | ||
| } | ||
| } | ||
| let series2 = { | ||
| title: 'Deaths', | ||
| x: Object.keys(data.h.timeline.deaths), | ||
| y: Object.values(data.h.timeline.deaths), | ||
| style: { | ||
| line: 'red' | ||
| } | ||
| } | ||
|
|
||
| let series3 = { | ||
| title: 'Recovered', | ||
| x: Object.keys(data.h.timeline.recovered), | ||
| y: Object.values(data.h.timeline.recovered), | ||
| style: { | ||
| line: 'green' | ||
| } | ||
| } | ||
|
|
||
| screen.append(line) //must append before setting data | ||
| line.setData([series1, series2, series3]) | ||
|
|
||
| let markdownFooter = grid.set(8, 0, 2, 9, contrib.markdown,{ | ||
| style: { | ||
| border: { | ||
| fg: 'black' | ||
| } | ||
| } | ||
| }) | ||
| markdownFooter.setMarkdown(data.footer) | ||
|
|
||
| return grid | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.