Skip to content

Commit 1f22dc8

Browse files
committed
mv obs
1 parent 1eb1810 commit 1f22dc8

File tree

2 files changed

+24
-53
lines changed

2 files changed

+24
-53
lines changed

ebird/server/server.go

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,9 @@ import (
1414
_ "github.com/mattn/go-sqlite3"
1515
)
1616

17-
// Sync with cmd/ebird_import.go
18-
type Obs struct {
19-
GlobalUniqueIdentifier string `json:"global_unique_identifier,omitempty"`
20-
LastEditedDate string `json:"last_edited_date,omitempty"`
21-
TaxonomicOrder string `json:"taxonomic_order,omitempty"`
22-
Category string `json:"category,omitempty"`
23-
CommonName string `json:"common_name,omitempty"`
24-
ScientificName string `json:"scientific_name,omitempty"`
25-
SubspeciesCommonName string `json:"subspecies_common_name,omitempty"`
26-
SubspeciesScientificName string `json:"subspecies_scientific_name,omitempty"`
27-
ObservationCount int `json:"observation_count,omitempty"`
28-
BreedingBirdAtlasCode string `json:"breeding_bird_atlas_code,omitempty"`
29-
BreedingBirdAtlasCategory string `json:"breeding_bird_atlas_category,omitempty"`
30-
AgeSex string `json:"age_sex,omitempty"`
31-
Country string `json:"country,omitempty"`
32-
CountryCode string `json:"country_code,omitempty"`
33-
State string `json:"state,omitempty"`
34-
StateCode string `json:"state_code,omitempty"`
35-
County string `json:"county,omitempty"`
36-
CountyCode string `json:"county_code,omitempty"`
37-
IBACode string `json:"iba_code,omitempty"`
38-
BCRCode string `json:"bcr_code,omitempty"`
39-
USFWSCode string `json:"usfws_code,omitempty"`
40-
AtlasBlock string `json:"atlas_block,omitempty"`
41-
Locality string `json:"locality"`
42-
LocalityID string `json:"locality_id,omitempty"`
43-
LocalityType string `json:"locality_type,omitempty"`
44-
Latitude float64 `json:"latitude,omitempty"`
45-
Longitude float64 `json:"longitude,omitempty"`
46-
ObservationDate string `json:"observation_date,omitempty"`
47-
TimeObservationsStarted string `json:"time_observations_started,omitempty"`
48-
ObserverID string `json:"observer_id,omitempty"`
49-
SamplingEventIdentifier string `json:"sampling_event_identifier,omitempty"`
50-
ProtocolType string `json:"protocol_type,omitempty"`
51-
ProtocolCode string `json:"protocol_code,omitempty"`
52-
ProjectCode string `json:"project_code,omitempty"`
53-
DurationMinutes int `json:"duration_minutes,omitempty"`
54-
EffortDistanceKM float64 `json:"effort_distance_km,omitempty"`
55-
EffortAreaHA float64 `json:"effort_area_ha,omitempty"`
56-
NumberObservers int `json:"number_observers,omitempty"`
57-
AllSpeciesReported bool `json:"all_species_reported,omitempty"`
58-
GroupIdentifier string `json:"group_identifier,omitempty"`
59-
HasMedia bool `json:"has_media,omitempty"`
60-
Approved bool `json:"approved,omitempty"`
61-
Reviewed bool `json:"reviewed,omitempty"`
62-
Reason string `json:"reason,omitempty"`
63-
TripComments string `json:"trip_comments"`
64-
SpeciesComments string `json:"species_comments"`
17+
func htmlHandler(w http.ResponseWriter, r *http.Request) {
18+
fmt.Fprintf(w, "<h1>Hello world!</h1>")
6519
}
66-
6720
func obsHandler(w http.ResponseWriter, r *http.Request) {
6821
row := db.QueryRow(`
6922
SELECT common_name, age_sex, observation_count, locality, longitude, latitude,
@@ -184,7 +137,8 @@ func main() {
184137
}
185138

186139
mux := &http.ServeMux{}
187-
mux.HandleFunc("/", obsHandler)
140+
mux.HandleFunc("/", htmlHandler)
141+
mux.HandleFunc("/obs", obsHandler)
188142
mux.HandleFunc("/species", speciesHandler)
189143
mux.HandleFunc("/codes", codeHandler)
190144
go func() {

tut/stat/stat.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,36 @@ import (
44
"math"
55
)
66

7+
const (
8+
flagMin = 1 << 0
9+
flagMax = 1 << 1
10+
flagStan = 1 << 2
11+
flagMean = 1 << 3
12+
flagClean = flagMin | flagMax | flagStan | flagMean
13+
)
14+
715
type Stats struct {
8-
data []float64
16+
data []float64
17+
min, max, stan, mean float64
18+
clean uint8
919
}
1020

1121
func (s *Stats) Add(x ...float64) { //append
1222
s.data = append(s.data, x...)
23+
s.clean = 0
1324
}
1425

1526
func (s *Stats) Mean() float64 {
27+
if s.clean&flagMean > 0 {
28+
return s.mean
29+
}
1630
mean := 0.0
1731
for _, x := range s.data {
1832
mean += x
1933
}
20-
return mean / float64(len(s.data)) //has to divide float by float, not float by integer
34+
s.mean = mean / float64(len(s.data))
35+
s.clean = s.clean | flagMean
36+
return s.mean
2137
}
2238

2339
func (s *Stats) Min() float64 {
@@ -42,8 +58,9 @@ func (s *Stats) Max() float64 {
4258

4359
func (s *Stats) Stan() float64 {
4460
stdev := 0.0
61+
mean := s.Mean()
4562
for _, x := range s.data {
46-
stdev += (x - s.Mean()) * (x - s.Mean())
63+
stdev += (x - mean) * (x - mean)
4764
}
4865
stdev = stdev / float64(len(s.data))
4966
stdev = math.Sqrt(stdev)

0 commit comments

Comments
 (0)