Skip to content

Instantly share code, notes, and snippets.

@myokoym
Last active August 29, 2015 14:06
Show Gist options
  • Save myokoym/8a52a6ed6477ca03de00 to your computer and use it in GitHub Desktop.
Save myokoym/8a52a6ed6477ca03de00 to your computer and use it in GitHub Desktop.
札幌市のゴミの日データを生成するRubyスクリプト(作成中) https://github.com/myokoym/5374
module Gominashi
SOURCES = [
{
name: "chuo_1",
areas: [
"中央区 南4条西7丁目・8丁目(南4条通の南側のみ),札幌センター1",
"中央区 南5条~8条の西7丁目・8丁目,札幌センター1",
"中央区 南9条西4丁目~6丁目(南9条通の南側のみ),札幌センター1",
"中央区 南9条西7丁目~12丁目,札幌センター1",
"中央区 南10条~13条の西5丁目~12丁目,札幌センター1",
"中央区 南14条西5丁目,札幌センター1",
"中央区 南14条西6丁目~12丁目(行啓通の北側のみ),札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["金"],
:paper => [],
:pet => ["火"],
},
special_day: "wednesday",
},
{
name: "chuo_2",
areas: [
"中央区 南14条西6丁目~12丁目(行啓通の南側のみ),札幌センター1",
"中央区 南15条西4丁目~12丁目,札幌センター1",
"中央区 南16条西1丁目~12丁目,札幌センター1",
"中央区 南17条西4丁目~15丁目,札幌センター1",
"中央区 南17条西16・17丁目(南17条通の南側のみ),札幌センター1",
"中央区 南18条~30条の西○丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["水"],
:paper => [],
:pet => ["金"],
},
special_day: "tuesday",
},
{
name: "chuo_3",
areas: [
"中央区 南3条西11丁目・12丁目(南3条通の南側のみ),札幌センター1",
"中央区 南4条西9丁目・10丁目(南4条通の南側のみ),札幌センター1",
"中央区 南4条西11丁目~27丁目,札幌センター1",
"中央区 南5条~8条の西9丁目~27丁目,札幌センター1",
"中央区 南9条~16条の西13丁目~23丁目,札幌センター1",
"中央区 南17条西16丁目・17丁目(南17条通の北側のみ),札幌センター1",
"中央区 南17条西18丁目,札幌センター1",
"中央区 円山・双子山・界川・旭ヶ丘・伏見,札幌センター1",
"中央区 円山西町(9丁目5番、6番のみ),札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["火"],
:paper => [],
:pet => ["水"],
},
special_day: "friday",
},
{
name: "chuo_4",
areas: [
"中央区 北1条西10丁目~19丁目(北1条通の北側のみ),札幌センター1",
"中央区 北2条西8丁目~19丁目,札幌センター1",
"中央区 北3条・4条の西8丁目~20丁目,札幌センター1",
"中央区 北5条~11条の西9丁目~20丁目,札幌センター1",
"中央区 北12条~14条の西15丁目~19丁目,札幌センター1",
"中央区 北15条~22条の西○丁目,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["水"],
:paper => [],
:pet => ["木"],
},
special_day: "monday",
},
{
name: "chuo_5",
areas: [
"中央区 大通西20丁目~28丁目,札幌センター1",
"中央区 南1条~3条の西20丁目~28丁目,札幌センター1",
"中央区 北1条・2条の西20丁目~28丁目,札幌センター1",
"中央区 北3条~11条の西21丁目~30丁目,札幌センター1",
"中央区 北12条西20丁目~23丁目,札幌センター1",
"中央区 北14条西20丁目,札幌センター1",
"中央区 宮の森・宮ヶ丘・盤渓,札幌センター1",
"中央区 円山西町(9丁目5番、6番を除く),札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["月"],
:paper => [],
:pet => ["水"],
},
special_day: "thursday",
},
{
name: "chuo_6",
areas: [
"中央区 大通西1丁目~19丁目,札幌センター1",
"中央区 大通東○丁目,札幌センター1",
"中央区 南○条東○丁目,札幌センター1",
"中央区 北○条東○丁目,札幌センター1",
"中央区 南1条・2条の西1丁目~19丁目,札幌センター1",
"中央区 南3条西1丁目~10丁目・13丁目~18丁目,札幌センター1",
"中央区 南3条西11丁目・12丁目(南3条通の北側のみ),札幌センター1",
"中央区 南4条西1丁目~6丁目,札幌センター1",
"中央区 南4条西7丁目~10丁目(南4条通の北側のみ),札幌センター1",
"中央区 南5条~8条の西1丁目~6丁目,札幌センター1",
"中央区 南9条西1丁目~3丁目,札幌センター1",
"中央区 南9条西4丁目~6丁目(南9条通の北側のみ),札幌センター1",
"中央区 南10条~15条の西1丁目~3丁目,札幌センター1",
"中央区 北1条西1丁目~9丁目,札幌センター1",
"中央区 北1条西10丁目~19丁目(北1条通の南側のみ),札幌センター1",
"中央区 北2条~4条の西1丁目~7丁目,札幌センター1",
"中央区 北5条西1丁目~8丁目,札幌センター1",
"中央区 中島公園,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["木"],
:paper => [],
:pet => ["月"],
},
special_day: "wednesday",
},
{
name: "atsubetsu_1",
areas: [
"厚別区 厚別西○条○丁目、○番地,札幌センター1",
"厚別区 厚別北○条○丁目,札幌センター1",
"厚別区 厚別町山本○番地,札幌センター1",
"厚別区 厚別町小野幌○番地(JR函館本線の北側),札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["火"],
:paper => [],
:pet => ["水"],
},
special_day: "friday",
},
{
name: "atsubetsu_2",
areas: [
"厚別区 厚別西○条○丁目、○番地,札幌センター1",
"厚別区 厚別中央2条~5条の○丁目,札幌センター1",
"厚別区 青葉町11丁目・12丁目、14丁目~16丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["火"],
:paper => [],
:pet => ["金"],
},
special_day: "wednesday",
},
{
name: "atsubetsu_3",
areas: [
"厚別区 厚別南○丁目,札幌センター1",
"厚別区 上野幌○条○丁目,札幌センター1",
"厚別区 厚別町上野幌○番地,札幌センター1",
"厚別区 大谷地西○丁目、東○丁目,札幌センター1",
"厚別区 青葉町1丁目~10丁目、13丁目,札幌センター1",
"厚別区 厚別中央1条5丁目・6丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["金"],
:paper => [],
:pet => ["火"],
},
special_day: "wednesday",
},
{
name: "atsubetsu_4",
areas: [
"厚別区 厚別東○条○丁目,札幌センター1",
"厚別区 厚別町下野幌○番地,札幌センター1",
"厚別区 もみじ台東・西・南・北の○丁目,札幌センター1",
"厚別区 厚別町小野幌○番地(JR函館本線の南側),札幌センター1",
"厚別区 下野幌テクノパーク○丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["水"],
:paper => [],
:pet => ["金"],
},
special_day: "tuesday",
},
{
name: "shiroishi_1",
areas: [
"白石区 中央○条○丁目,札幌センター1",
"白石区 本通1丁目~14丁目(南北),札幌センター1",
"白石区 平和通1丁目~14丁目(南北),札幌センター1",
"白石区 本郷通1丁目~13丁目(南北),札幌センター1",
"白石区 南郷通1丁目~14丁目(南北),札幌センター1",
"白石区 栄通1丁目~14丁目,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["月"],
:paper => [],
:pet => ["木"],
},
special_day: "wednesday",
},
{
name: "shiroishi_2",
areas: [
"白石区 北郷○条○丁目、○番地,札幌センター1",
"白石区 川北○条○丁目、○番地,札幌センター1",
"白石区 川下○条○丁目、○番地,札幌センター1",
"白石区 菊水元町○条○丁目,札幌センター1",
"白石区 東米里○番地,札幌センター1",
"白石区 米里○条○丁目,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["木"],
:paper => [],
:pet => ["水"],
},
special_day: "monday",
},
{
name: "shiroishi_3",
areas: [
"白石区 東札幌○条○丁目,札幌センター1",
"白石区 菊水○条○丁目,札幌センター1",
"白石区 菊水上町○条○丁目,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["水"],
:paper => [],
:pet => ["月"],
},
special_day: "thursday",
},
{
name: "shiroishi_4",
areas: [
"白石区 本通15丁目~21丁目(南北),札幌センター1",
"白石区 平和通15丁目~17丁目(南北),札幌センター1",
"白石区 南郷通15丁目~21丁目(南北),札幌センター1",
"白石区 栄通15丁目~21丁目,札幌センター1",
"白石区 流通センター1丁目~7丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["金"],
:paper => [],
:pet => ["火"],
},
special_day: "wednesday",
},
]
end
require "date"
require "./5374-sources"
module Gominashi
class Util
class << self
SOURCES.each do |source|
define_method(source[:name]) do |begin_date = source[:begin_date],
end_date = source[:end_date],
special_order = source[:special_order]|
days = days(begin_date,
end_date,
source[:types],
source[:special_day],
special_order)
source[:areas].collect do |area|
"#{area},#{days}"
end
end
end
private
def days(begin_date, end_date, types, special_day, special_order)
special_dates = []
current_date = Date.parse(begin_date)
end_date = Date.parse(end_date)
current_special_date = nil
7.times do
if current_date.send("#{special_day}?")
current_special_date = current_date
break
end
current_date += 1
end
raise "ぬるぽ" unless current_special_date
loop do
break unless current_special_date < end_date
special_dates << current_special_date
current_special_date += 7
end
special_dates.reject! do |date|
# TODO: 年末年始は要確認
/\A(1231|010[1-6])\z/ =~ date.strftime("%m%d")
end
special_dates.each_slice(special_order.size) do |dates|
dates.each_with_index do |date, i|
type = special_order[i]
next if type == :leaf and [12, 1, 2, 3, 4].include?(date.month)
types[type] << date.strftime("%Y%m%d")
end
end
types.values.collect {|group|
group.join(" ")
}.join(",")
end
end
end
end
if $0 == __FILE__
special_order = [:paper, :not_burn, :paper, :leaf]
puts Gominashi::Util.chuo_1("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.chuo_2("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.chuo_3("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.chuo_4("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.chuo_5("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.chuo_6("2014-09-01", "2015-10-01", special_order)
special_order = [:leaf, :paper, :not_burn, :paper]
puts Gominashi::Util.atsubetsu_1("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.atsubetsu_2("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.atsubetsu_3("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.atsubetsu_4("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.shiroishi_1("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.shiroishi_2("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.shiroishi_3("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.shiroishi_4("2014-09-01", "2015-10-01", special_order)
end
CC0 1.0 Universal (Public Domain)
http://creativecommons.org/publicdomain/zero/1.0/deed.ja
require "test-unit"
require "./5374-util"
class GominashiUtilTest < Test::Unit::TestCase
def test_shiroishi_1
expected = [
"白石区 中央○条○丁目,札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 本通1丁目~14丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 平和通1丁目~14丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 本郷通1丁目~13丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 南郷通1丁目~14丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 栄通1丁目~14丁目,札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_1("2014-02-26",
"2014-09-30",
special_order))
end
def test_shiroishi_2
expected = [
"白石区 北郷○条○丁目、○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 川北○条○丁目、○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 川下○条○丁目、○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 菊水元町○条○丁目,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 東米里○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 米里○条○丁目,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_2("2014-02-24",
"2014-09-30",
special_order))
end
def test_shiroishi_3
expected = [
"白石区 東札幌○条○丁目,札幌センター1,火 金,20140515 20140612 20140710 20140807 20140904,20140306 20140403 20140501 20140529 20140626 20140724 20140821 20140918,水,20140227 20140313 20140327 20140410 20140424 20140508 20140522 20140605 20140619 20140703 20140717 20140731 20140814 20140828 20140911 20140925,月",
"白石区 菊水○条○丁目,札幌センター1,火 金,20140515 20140612 20140710 20140807 20140904,20140306 20140403 20140501 20140529 20140626 20140724 20140821 20140918,水,20140227 20140313 20140327 20140410 20140424 20140508 20140522 20140605 20140619 20140703 20140717 20140731 20140814 20140828 20140911 20140925,月",
"白石区 菊水上町○条○丁目,札幌センター1,火 金,20140515 20140612 20140710 20140807 20140904,20140306 20140403 20140501 20140529 20140626 20140724 20140821 20140918,水,20140227 20140313 20140327 20140410 20140424 20140508 20140522 20140605 20140619 20140703 20140717 20140731 20140814 20140828 20140911 20140925,月",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_3("2014-02-27",
"2014-09-30",
special_order))
end
def test_shiroishi_4
expected = [
"白石区 本通15丁目~21丁目(南北),札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 平和通15丁目~17丁目(南北),札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 南郷通15丁目~21丁目(南北),札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 栄通15丁目~21丁目,札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 流通センター1丁目~7丁目,札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_4("2014-02-26",
"2014-09-30",
special_order))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment