compressed timings

This commit is contained in:
Radu Ioan Fericean
2012-06-13 13:36:57 +03:00
parent 05c3229920
commit 7f5ddf9bf4
7 changed files with 28 additions and 101 deletions

View File

@@ -65,7 +65,6 @@ func writeToDatabase() {
func main() {
flag.Parse()
sep = []rune(*separator)[0]
loadDataSeries()
loadDestinations()
loadRates()
loadTimings()

View File

@@ -61,16 +61,19 @@ func NewRate(destinationsTag, connectFee, price, billingUnit, weight string) (r
}
type Timing struct {
MonthsTag, MonthDaysTag, WeekDaysTag, StartTime string
Months timespans.Months
MonthDays timespans.MonthDays
WeekDays timespans.WeekDays
StartTime string
}
func NewTiming(timeingInfo ...string) (rt *Timing) {
rt = &Timing{
MonthsTag: timeingInfo[0],
MonthDaysTag: timeingInfo[1],
WeekDaysTag: timeingInfo[2],
StartTime: timeingInfo[3],
StartTime: timeingInfo[3],
}
rt.Months.Parse(timeingInfo[0], ";")
rt.MonthDays.Parse(timeingInfo[1], ";")
rt.WeekDays.Parse(timeingInfo[2], ";")
return
}
@@ -89,9 +92,9 @@ func NewRateTiming(ratesTag string, timing *Timing) (rt *RateTiming) {
func (rt *RateTiming) GetInterval(r *Rate) (i *timespans.Interval) {
i = &timespans.Interval{
Months: timespans.Months(months[rt.timing.MonthsTag]),
MonthDays: timespans.MonthDays(monthdays[rt.timing.MonthDaysTag]),
WeekDays: timespans.WeekDays(weekdays[rt.timing.WeekDaysTag]),
Months: rt.timing.Months,
MonthDays: rt.timing.MonthDays,
WeekDays: rt.timing.WeekDays,
StartTime: rt.timing.StartTime,
ConnectFee: r.ConnectFee,
Price: r.Price,

View File

@@ -27,9 +27,6 @@ import (
)
var (
months = make(map[string][]time.Month)
monthdays = make(map[string][]int)
weekdays = make(map[string][]time.Weekday)
destinations []*timespans.Destination
rates = make(map[string][]*Rate)
timings = make(map[string][]*Timing)
@@ -37,75 +34,6 @@ var (
ratingProfiles = make(map[string]CallDescriptors)
)
func loadDataSeries() {
// MONTHS
fp, err := os.Open(*monthsFn)
if err != nil {
log.Printf("Could not open months file: %v", err)
} else {
csvReader := csv.NewReader(fp)
csvReader.Comma = sep
for record, err := csvReader.Read(); err == nil; record, err = csvReader.Read() {
tag := record[0]
if tag == "Tag" {
// skip header line
continue
}
for i, m := range record[1:] {
if m == "1" {
months[tag] = append(months[tag], time.Month(i+1))
}
}
log.Print(tag, months[tag])
}
fp.Close()
}
// MONTH DAYS
fp, err = os.Open(*monthdaysFn)
if err != nil {
log.Printf("Could not open month days file: %v", err)
} else {
csvReader := csv.NewReader(fp)
csvReader.Comma = sep
for record, err := csvReader.Read(); err == nil; record, err = csvReader.Read() {
tag := record[0]
if tag == "Tag" {
// skip header line
continue
}
for i, m := range record[1:] {
if m == "1" {
monthdays[tag] = append(monthdays[tag], i+1)
}
}
log.Print(tag, monthdays[tag])
}
fp.Close()
}
// WEEK DAYS
fp, err = os.Open(*weekdaysFn)
if err != nil {
log.Printf("Could not open week days file: %v", err)
} else {
csvReader := csv.NewReader(fp)
csvReader.Comma = sep
for record, err := csvReader.Read(); err == nil; record, err = csvReader.Read() {
tag := record[0]
if tag == "Tag" {
// skip header line
continue
}
for i, m := range record[1:] {
if m == "1" {
weekdays[tag] = append(weekdays[tag], time.Weekday(((i + 1) % 7)))
}
}
log.Print(tag, weekdays[tag])
}
fp.Close()
}
}
func loadDestinations() {
fp, err := os.Open(*destinationsFn)
if err != nil {

View File

@@ -1,6 +0,0 @@
Tag,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
ALL,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
CHRISTMAS_DAY,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0
VALENTINES_DAY,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
20th,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0
FIRST,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1 Tag 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2 ALL 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 CHRISTMAS_DAY 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
4 VALENTINES_DAY 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
5 20th 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
6 FIRST 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

View File

@@ -1,7 +0,0 @@
Tag,January,February,March,April,May,June,Jully,August,September,October,November,December
ALL,1,1,1,1,1,1,1,1,1,1,1,1
WINTER,1,1,0,0,0,0,0,0,0,0,0,1
SPRING,0,0,1,1,1,0,0,0,0,0,0,0
SUMMER,0,0,0,0,0,1,1,1,0,0,0,0
AUTUMN,0,0,0,0,0,0,0,0,1,1,1,0
JANUARY,1,0,0,0,0,0,0,0,0,0,0,0
1 Tag January February March April May June Jully August September October November December
2 ALL 1 1 1 1 1 1 1 1 1 1 1 1
3 WINTER 1 1 0 0 0 0 0 0 0 0 0 1
4 SPRING 0 0 1 1 1 0 0 0 0 0 0 0
5 SUMMER 0 0 0 0 0 1 1 1 0 0 0 0
6 AUTUMN 0 0 0 0 0 0 0 0 1 1 1 0
7 JANUARY 1 0 0 0 0 0 0 0 0 0 0 0

View File

@@ -1,4 +0,0 @@
Tag,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
ALL,1,1,1,1,1,1,1
WORKDAYS,1,1,1,1,1,0,0
WEEKENDS,0,0,0,0,0,1,1
1 Tag Monday Tuesday Wednesday Thursday Friday Saturday Sunday
2 ALL 1 1 1 1 1 1 1
3 WORKDAYS 1 1 1 1 1 0 0
4 WEEKENDS 0 0 0 0 0 1 1

View File

@@ -55,7 +55,12 @@ func (m Months) store() (result string) {
De-serializes the month for the storage. Used for key-value storages.
*/
func (m *Months) restore(input string) {
elements := strings.Split(input, ",")
m.Parse(input, ",")
}
// Loades Month elemnents from a string separated by sep.
func (m *Months) Parse(input, sep string) {
elements := strings.Split(input, sep)
for _, ms := range elements {
if month, err := strconv.Atoi(ms); err == nil {
*m = append(*m, time.Month(month))
@@ -93,7 +98,12 @@ func (md MonthDays) store() (result string) {
De-serializes the month days for the storage. Used for key-value storages.
*/
func (md *MonthDays) restore(input string) {
elements := strings.Split(input, ",")
md.Parse(input, ",")
}
// Parse MonthDay elements from string separated by sep.
func (md *MonthDays) Parse(input, sep string) {
elements := strings.Split(input, sep)
for _, mds := range elements {
if day, err := strconv.Atoi(mds); err == nil {
*md = append(*md, day)
@@ -131,7 +141,11 @@ func (wd WeekDays) store() (result string) {
De-serializes the week days for the storage. Used for key-value storages.
*/
func (wd *WeekDays) restore(input string) {
elements := strings.Split(input, ",")
wd.Parse(input, ",")
}
func (wd *WeekDays) Parse(input, sep string) {
elements := strings.Split(input, sep)
for _, wds := range elements {
if day, err := strconv.Atoi(wds); err == nil {
*wd = append(*wd, time.Weekday(day))