Skip to content

Instantly share code, notes, and snippets.

@kevinburke
Last active February 19, 2018 05:18
Show Gist options
  • Save kevinburke/72659fe22d1c84fe2eb47fa418e3052b to your computer and use it in GitHub Desktop.
Save kevinburke/72659fe22d1c84fe2eb47fa418e3052b to your computer and use it in GitHub Desktop.
2010 2011 2012 2013 2014 2015 2016 2017
10th %ile: 909.7 1315.7 (144.6%) 1400.0 (106.4%) 1675.0 (119.6%) 1748.3 (104.4%) 2000.0 (114.4%) 2195.0 (109.8%) 2000.0 (91.1%)
20th %ile: 1115.0 1783.0 (159.9%) 1850.0 (103.8%) 2100.0 (113.5%) 2200.0 (104.8%) 2600.0 (118.2%) 2600.0 (100.0%) 2500.0 (96.2%)
30th %ile: 1650.0 2099.0 (127.2%) 2199.0 (104.8%) 2500.0 (113.7%) 2695.0 (107.8%) 2975.6 (110.4%) 2995.0 (100.7%) 2850.0 (95.2%)
40th %ile: 1800.0 2399.0 (133.3%) 2462.0 (102.6%) 2800.0 (113.7%) 3000.0 (107.1%) 3250.0 (108.3%) 3400.0 (104.6%) 3191.3 (93.9%)
50th %ile: 2084.0 2600.0 (124.8%) 2700.0 (103.8%) 3195.0 (118.3%) 3395.0 (106.3%) 3525.0 (103.8%) 3750.0 (106.4%) 3500.0 (93.3%)
60th %ile: 2334.0 2995.0 (128.3%) 3000.0 (100.2%) 3500.0 (116.7%) 3700.0 (105.7%) 3895.0 (105.3%) 4154.3 (106.7%) 3900.0 (93.9%)
70th %ile: 2565.0 3500.0 (136.5%) 3495.0 (99.9%) 4200.0 (120.2%) 4200.0 (100.0%) 4375.0 (104.2%) 4695.0 (107.3%) 4350.0 (92.7%)
80th %ile: 2890.0 4250.0 (147.1%) 4000.0 (94.1%) 5160.0 (129.0%) 4900.0 (95.0%) 4950.0 (101.0%) 5377.0 (108.6%) 4900.0 (91.1%)
90th %ile: 3735.3 5998.3 (160.6%) 5465.0 (91.1%) 7250.0 (132.7%) 6250.0 (86.2%) 6417.0 (102.7%) 6500.0 (101.3%) 5995.7 (92.2%)
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"regexp"
"sort"
"strconv"
"github.com/kevinburke/housing-inventory-analysis/stats"
)
var parseRx = regexp.MustCompile(`\$[0-9]{2,10}`)
func getPrice(linePrices []string) int {
if len(linePrices) == 0 {
return -1
}
prices := make([]int, len(linePrices))
for i := range linePrices {
if len(linePrices[i]) < 2 {
panic("too short: " + linePrices[i])
}
price, err := strconv.Atoi(linePrices[i][1:])
if err != nil {
panic(err)
}
prices[i] = price
}
if len(linePrices) == 1 {
return prices[0]
}
if prices[0] < 200 && prices[1] < 200 {
return -1
}
if prices[1] > prices[0] {
return prices[1]
}
return prices[0]
}
func main() {
flag.Parse()
samples := make([]stats.Sample, 0)
for i := 0; i < flag.NArg(); i++ {
f, err := os.Open(flag.Arg(i))
if err != nil {
log.Fatal(err)
}
defer f.Close()
bs := bufio.NewScanner(f)
prices := make([]float64, 0)
for bs.Scan() {
linePrices := parseRx.FindAllString(bs.Text(), -1)
if len(linePrices) > 0 {
price := getPrice(linePrices)
if price < 0 || price > 100000 {
// sf is expensive, but not *that* expensive
continue
}
prices = append(prices, float64(price))
}
}
if err := bs.Err(); err != nil {
log.Fatal(err)
}
sort.Float64s(prices)
samples = append(samples, stats.Sample{Xs: prices})
}
fmt.Printf("total: ")
for i := 0; i < len(samples); i++ {
if i > 0 {
fmt.Printf("%14d\t", len(samples[i].Xs))
} else {
fmt.Printf("%11d\t", len(samples[i].Xs))
}
}
fmt.Printf("\n")
for i := float64(1); i <= 9; i++ {
fmt.Printf("%dth %%ile: ", int(i)*10)
for j := 0; j < len(samples); j++ {
fmt.Printf("%8.1f ", samples[j].Percentile(0.1*i))
if j > 0 {
diff := 100 * samples[j].Percentile(0.1*i) / samples[j-1].Percentile(0.1*i)
fmt.Printf("(%.1f%%)\t", diff)
}
}
fmt.Printf("\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment