Last active
August 29, 2015 14:22
-
-
Save bcho/24222f3f23cd14057092 to your computer and use it in GitHub Desktop.
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
| fs = require 'fs' | |
| path = require 'path' | |
| dataPath = './data' | |
| fullPath = (name) -> path.join dataPath, name | |
| evalFile = (name) -> eval fs.readFileSync(fullPath name).toString 'utf8' | |
| files = fs.readdirSync dataPath | |
| merged = [] | |
| merged = merged.concat.apply merged, files.map evalFile | |
| fs.writeFileSync 'output.json', JSON.stringify merged |
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
| fs = require 'fs' | |
| path = require 'path' | |
| dataPath = './data' | |
| fullPath = (name) -> path.join dataPath, name | |
| evalFile = (name) -> JSON.parse fs.readFileSync(fullPath name).toString 'utf8' | |
| files = fs.readdirSync dataPath | |
| merged = files.map evalFile | |
| fs.writeFileSync 'output.json', JSON.stringify merged |
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
| fs = require 'fs' | |
| path = require 'path' | |
| dataPath = './data' | |
| fullPath = (name) -> path.join dataPath, name | |
| gz_obtDatas = null # should catch by the closure | |
| evalFile = (name) -> | |
| console.log name | |
| try | |
| eval fs.readFileSync(fullPath name).toString 'utf8' | |
| gz_obtDatas | |
| catch e | |
| console.log e | |
| groupBy = (coll, f) -> | |
| groups = {} | |
| coll.forEach (c) -> | |
| group = f(c) | |
| groups[group] = [] unless groups[group]? | |
| groups[group].push c | |
| groups | |
| files = fs.readdirSync dataPath | |
| byMonths = groupBy files, (name) -> (new Date(name)).getMonth() + 1 | |
| byMonthsAndWeeks = {} | |
| for month, files of byMonths | |
| byMonthsAndWeeks[month] = groupBy files, (name) -> | |
| (Math.round (new Date(name)).getDate() / 7) + 1 | |
| for month, byWeeks of byMonthsAndWeeks | |
| for week, files of byWeeks | |
| merged = (files.map evalFile).filter (x) -> x? | |
| fs.writeFileSync "#{month}-#{week}.json", JSON.stringify merged |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment