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()