(data.csv)
1 2 3 4 5 6 7 8 9 10 11 |
プログラミング言語,リクナビNext,DODA,パイザ,キャリコネ,Indeed HTML,117,256,283,1642,7643 JavaScript,104,380,889,2362,7093 PHP,248,722,866,3605,9319 Java,484,1729,990,5372,15893 Python,87,301,255,1606,3378 C++,1172,701,393,998,5897 C#,1172,669,552,882,6412 Swift,34,92,278,805,1129 Ruby,83,286,464,2200,3919 R,5,8,26,22,313 |
(Main.js)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
const main = () => { const p = console.log const fs = require('fs') class Agent { constructor(name, html, js, php, java, python, cp, cs, swift, ruby, r) { this.name = name this.html = Number(html) this.js = Number(js) this.php = Number(php) this.java = Number(java) this.python = Number(python) this.cp = Number(cp) this.cs = Number(cs) this.swift = Number(swift) this.ruby = Number(ruby) this.r = Number(r) this.updateShare() } calcSum() { return this.html + this.js + this.php + this.java + this.python + this.cp + this.cs + this.swift + this.ruby + this.r } updateShare() { const sum = this.calcSum() this.htmlShare = 100 * this.html / sum this.jsShare = 100 * this.js / sum this.phpShare = 100 * this.php / sum this.javaShare = 100 * this.java / sum this.pythonShare = 100 * this.python / sum this.cpShare = 100 * this.cp / sum this.csShare = 100 * this.cs / sum this.swiftShare = 100 * this.swift / sum this.rubyShare = 100 * this.ruby / sum this.rShare = 100 * this.r / sum } } const convertDataTo2dArray = data => { const a = [] data.split('\n').forEach(line => { a.push(line.split(',')) }) return a } const convert2dArrayToAgents = a => { const agents = {} agents.rnn = new Agent(a[0][1], a[1][1], a[2][1], a[3][1], a[4][1], a[5][1], a[6][1], a[7][1], a[8][1], a[9][1], a[10][1]) agents.doda = new Agent(a[0][2], a[1][2], a[2][2], a[3][2], a[4][2], a[5][2], a[6][2], a[7][2], a[8][2], a[9][2], a[10][2]) agents.paiza = new Agent(a[0][3], a[1][3], a[2][3], a[3][3], a[4][3], a[5][3], a[6][3], a[7][3], a[8][3], a[9][3], a[10][3]) agents.cc = new Agent(a[0][4], a[1][4], a[2][4], a[3][4], a[4][4], a[5][4], a[6][4], a[7][4], a[8][4], a[9][4], a[10][4]) agents.indeed = new Agent(a[0][5], a[1][5], a[2][5], a[3][5], a[4][5], a[5][5], a[6][5], a[7][5], a[8][5], a[9][5], a[10][5]) return agents } const calcHtmlShareAverage = agents => (agents.rnn.htmlShare + agents.doda.htmlShare + agents.paiza.htmlShare + agents.cc.htmlShare + agents.indeed.htmlShare) / 5 const calcJsShareAverage = agents => (agents.rnn.jsShare + agents.doda.jsShare + agents.paiza.jsShare + agents.cc.jsShare + agents.indeed.jsShare) / 5 const calcPhpShareAverage = agents => (agents.rnn.phpShare + agents.doda.phpShare + agents.paiza.phpShare + agents.cc.phpShare + agents.indeed.phpShare) / 5 const calcJavaShareAverage = agents => (agents.rnn.javaShare + agents.doda.javaShare + agents.paiza.javaShare + agents.cc.javaShare + agents.indeed.javaShare) / 5 const calcPythonShareAverage = agents => (agents.rnn.pythonShare + agents.doda.pythonShare + agents.paiza.pythonShare + agents.cc.pythonShare + agents.indeed.pythonShare) / 5 const calcCpShareAverage = agents => (agents.rnn.cpShare + agents.doda.cpShare + agents.paiza.cpShare + agents.cc.cpShare + agents.indeed.cpShare) / 5 const calcCsShareAverage = agents => (agents.rnn.csShare + agents.doda.csShare + agents.paiza.csShare + agents.cc.csShare + agents.indeed.csShare) / 5 const calcSwiftShareAverage = agents => (agents.rnn.swiftShare + agents.doda.swiftShare + agents.paiza.swiftShare + agents.cc.swiftShare + agents.indeed.swiftShare) / 5 const calcRubyShareAverage = agents => (agents.rnn.rubyShare + agents.doda.rubyShare + agents.paiza.rubyShare + agents.cc.rubyShare + agents.indeed.rubyShare) / 5 const calcRShareAverage = agents => (agents.rnn.rShare + agents.doda.rShare + agents.paiza.rShare + agents.cc.rShare + agents.indeed.rShare) / 5 const sub = () => { const d = fs.readFileSync("data.csv", {encoding: "utf-8"}) const a = convertDataTo2dArray(d) const o = convert2dArrayToAgents(a) p('HtmlShareAverage : ', calcHtmlShareAverage (o)) p('JsShareAverage : ', calcJsShareAverage (o)) p('PhpShareAverage : ', calcPhpShareAverage (o)) p('JavaShareAverage : ', calcJavaShareAverage (o)) p('PythonShareAverage : ', calcPythonShareAverage(o)) p('CpShareAverage : ', calcCpShareAverage (o)) p('CsShareAverage : ', calcCsShareAverage (o)) p('SwiftShareAverage : ', calcSwiftShareAverage (o)) p('RubyShareAverage : ', calcRubyShareAverage (o)) p('RShareAverage : ', calcRShareAverage (o)) } sub() } main() |
1 2 3 4 5 6 7 8 9 10 |
HtmlShareAverage : 6.986354843278131 JsShareAverage : 10.378601229059685 PhpShareAverage : 14.44282913557401 JavaShareAverage : 24.16914753977421 PythonShareAverage : 5.442704295588216 CpShareAverage : 13.941919944259928 CsShareAverage : 14.503864909656471 SwiftShareAverage : 2.860625180852734 RubyShareAverage : 6.985042195338946 RShareAverage : 0.28891072661766853 |