Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.io._
- import java.io.File
- import java.util.{Date, Calendar}
- import java.lang.reflect.Field
- import java.lang.IllegalAccessException
- case class Ticker(line: String) {
- val data = line.split(",")
- val currency = data(0)
- val open = data(3).toDouble
- val high = data(4).toDouble
- val low = data(5).toDouble
- val close = data(6).toDouble
- val datetime = calcDateTime( data(1).slice(0,4).toInt,
- data(1).slice(4,6).toInt,
- data(1).slice(6,8).toInt,
- data(2).slice(0,2).toInt,
- data(2).slice(2,4).toInt )
- def calcDateTime(year : Int, month : Int, day : Int, hour : Int, min : Int) : Date = {
- val cal = Calendar.getInstance()
- cal.set(year, month, day, hour, min)
- cal.add(Calendar.HOUR, 1)
- cal.getTime
- }
- override def toString() = {
- try {
- getClass().getDeclaredFields().map { field:Field =>
- field.setAccessible(true)
- field.getName() + ": " + field.getType() + " = " + field.get(this).toString()
- }.deep.mkString("\n")
- }
- catch
- {
- case iae : IllegalAccessException => "Failed to get field"
- }
- }
- }
- object ImportForex
- {
- def main(args : Array[String]) {
- Console.println("Starting")
- val db = connectToDB
- val datadir = new File("data/")
- datadir.listFiles.foreach { f =>
- Console.println(f)
- Source.fromFile(f).getLines.foreach { l =>
- store( Ticker(l) )
- }
- }
- }
- def store(ticker : Ticker) {
- Console.println(ticker)
- }
- def connectToDB = 1
- }
Add Comment
Please, Sign In to add comment