<commit_before>package weather

import (
	"sync"
	"time"

	"code.google.com/r/skirodriguez-dbf/godbf"
)

var cachedDbfTable = new(CachedDbfTable)

const (
	rainSum  = "RAIN_SUM"
	presLoc  = "PRES_LOC"
	presAbs  = "PRES_ABS"
	chn1Deg  = "CHN1_DEG"
	chn1Dew  = "CHN1_DEW"
	chn1Rf   = "CHN1_RF"
	dateTime = "DATE_TIME"
)

type CachedDbfTable struct {
	DbfTable  *godbf.DbfTable
	updatedAt time.Time
	sync.RWMutex
}

type WeatherRecord struct {
	Datetime         time.Time
	LocalPressure    float64
	AbsolutePressure float64
	Temperature      float64
	DewPoint         float64
	RainSum          float64
	RelativeHumidity float64
}

func getDbf() (*godbf.DbfTable, error) {
	var err error
	table := new(godbf.DbfTable)
	cachedDbfTable.RLock()
	needsUpdate := cachedDbfTable.updatedAt.Add(time.Minute*20).Before(time.Now()) || cachedDbfTable.DbfTable == nil
	if !needsUpdate {
		*table = *cachedDbfTable.DbfTable
	}
	cachedDbfTable.RUnlock()
	if needsUpdate {
		cachedDbfTable.Lock()
		dbfPath := "/Users/pedro/Downloads/chapelco.dbf"
		//dbfPath := "http://googledrive.com/host/0B06ZoNF0o91ncXRPdVRuZjBDaE0"
		cachedDbfTable.DbfTable, err = godbf.NewFromFile(dbfPath, "UTF8")
		cachedDbfTable.updatedAt = time.Now()
		*table = *cachedDbfTable.DbfTable
		cachedDbfTable.Unlock()
	}
	return table, err<commit_msg>Fixed using file instead of url (file is for testing)<commit_after>package weather

import (
	"sync"
	"time"

	"code.google.com/r/skirodriguez-dbf/godbf"
)

var cachedDbfTable = new(CachedDbfTable)

const (
	rainSum  = "RAIN_SUM"
	presLoc  = "PRES_LOC"
	presAbs  = "PRES_ABS"
	chn1Deg  = "CHN1_DEG"
	chn1Dew  = "CHN1_DEW"
	chn1Rf   = "CHN1_RF"
	dateTime = "DATE_TIME"
)

type CachedDbfTable struct {
	DbfTable  *godbf.DbfTable
	updatedAt time.Time
	sync.RWMutex
}

type WeatherRecord struct {
	Datetime         time.Time
	LocalPressure    float64
	AbsolutePressure float64
	Temperature      float64
	DewPoint         float64
	RainSum          float64
	RelativeHumidity float64
}

func getDbf() (*godbf.DbfTable, error) {
	var err error
	table := new(godbf.DbfTable)
	cachedDbfTable.RLock()
	needsUpdate := cachedDbfTable.updatedAt.Add(time.Minute*20).Before(time.Now()) || cachedDbfTable.DbfTable == nil
	if !needsUpdate {
		*table = *cachedDbfTable.DbfTable
	}
	cachedDbfTable.RUnlock()
	if needsUpdate {
		cachedDbfTable.Lock()
		//dbfPath := "/Users/pedro/Downloads/chapelco.dbf"
		dbfPath := "http://googledrive.com/host/0B06ZoNF0o91ncXRPdVRuZjBDaE0"
		cachedDbfTable.DbfTable, err = godbf.NewFromUrl(dbfPath, "UTF8")
		cachedDbfTable.updatedAt = time.Now()
		*table = *cachedDbfTable.DbfTable
		cachedDbfTable.Unlock()
	}
	return table, err
{'fraction_non_alphanumeric': 0.11014711429649189, 'fraction_numerical': 0.021124104111655977, 'mean_word_length': 4.1796875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '764545', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1076, 'n_words': 182}