Skip to content

Instantly share code, notes, and snippets.

@seratch
Created April 23, 2011 16:32
Show Gist options
  • Save seratch/938761 to your computer and use it in GitHub Desktop.
Save seratch/938761 to your computer and use it in GitHub Desktop.
東京電力/過去30日の電力使用状況(各日18時台)
// see also https://github.com/seratch/yahoo-setsuden-api-client
// invoke Scala REPL
// scala -cp yahoo-setsuden-api-client*:joda-time*
import com.github.seratch.yahooapis.setsuden.scala._
import request._
import response._
import org.joda.time.LocalDate
val applicationId = "*****"
val client = new SetsudenYahooApiClient(applicationId)
val today = new LocalDate
val dayOfWeek = Map(1 -> "Mon", 2 -> "Tue", 3 -> "Web", 4 -> "Thu", 5 -> "Fri", 6 -> "Sat", 7 -> "Sun")
(1 to 30).reverse foreach {
daysAgo => {
val day = today.minusDays(daysAgo)
val yyyymmddhh = "2011" + "%02d".format(day.monthOfYear.get) + "%02d".format(day.dayOfMonth.get) + "18"
val dow = dayOfWeek.get(day.dayOfWeek.get).get
val result = client.getLatestPowerUsage(RequestParameters(yyyymmddhh = yyyymmddhh)).electricPowerUsage
val usage = result.usageKilowattPerHour
val capacity = result.capacityKilowattPerHour
println(yyyymmddhh + "(" + dow + ") : " + usage + " / " + capacity + " -> " + "%.1f".format(usage.doubleValue/capacity*100) + "%")
}
}
// result
/*
2011032518(Fri) : 34800000 / 37500000 -> 92.8%
2011032618(Sat) : 34330000 / 37000000 -> 92.8%
2011032718(Sun) : 33710000 / 37000000 -> 91.1%
2011032818(Mon) : 34900000 / 38500000 -> 90.6%
2011032918(Tue) : 33680000 / 38000000 -> 88.6%
2011033018(Web) : 33200000 / 38000000 -> 87.4%
2011033118(Thu) : 33880000 / 37500000 -> 90.3%
2011040118(Fri) : 32980000 / 37500000 -> 87.9%
2011040218(Sat) : 30650000 / 36500000 -> 84.0%
2011040318(Sun) : 33030000 / 36500000 -> 90.5%
2011040418(Mon) : 35180000 / 38500000 -> 91.4%
2011040518(Tue) : 34260000 / 39500000 -> 86.7%
2011040618(Web) : 33160000 / 40500000 -> 81.9%
2011040718(Thu) : 32950000 / 39500000 -> 83.4%
2011040818(Fri) : 32760000 / 38000000 -> 86.2%
2011040918(Sat) : 31550000 / 37500000 -> 84.1%
2011041018(Sun) : 30010000 / 39500000 -> 76.0%
2011041118(Mon) : 33260000 / 42500000 -> 78.3%
2011041218(Tue) : 34070000 / 41000000 -> 83.1%
2011041318(Web) : 33040000 / 41500000 -> 79.6%
2011041418(Thu) : 32800000 / 40000000 -> 82.0%
2011041518(Fri) : 32690000 / 40000000 -> 81.7%
2011041618(Sat) : 30000000 / 37500000 -> 80.0%
2011041718(Sun) : 29740000 / 37000000 -> 80.4%
2011041818(Mon) : 33570000 / 41000000 -> 81.9%
2011041918(Tue) : 35750000 / 40500000 -> 88.3%
2011042018(Web) : 34230000 / 41000000 -> 83.5%
2011042118(Thu) : 34870000 / 40000000 -> 87.2%
2011042218(Fri) : 33650000 / 38500000 -> 87.4%
2011042318(Sat) : 31650000 / 35000000 -> 90.4%
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment