<commit_before>package tracking

import (
	"encoding/json"
	"net/http"
	"time"

	"gopkg.in/mgo.v2/bson"
)

// Route represents a set of coordinates to draw a path on our tracking map
type Route struct {
	Id          bson.ObjectId `json:"id"             bson:"_id,omitempty"`
	Name        string        `json:"name"           bson:"name"`
	Description string        `json:"description"    bson:"description"`
	StartTime   string        `json:"startTime"      bson:"startTime"`
	EndTime     string        `json:"endTime"        bson:"endTime"`
	Enabled     bool          `json:"enabled,string" bson:"enabled"`
	Color       string        `json:"color"          bson:"color"`
	Width       int           `json:"width,string"   bson:"width"`
	Coords      string        `json:"coords"         bson:"coords"`
	Created     time.Time     `json:"created"        bson:"created"`
	Updated     time.Time     `json:"updated"        bson:"updated"`
}

// Stop indicates where a tracked object is scheduled to arrive
type Stop struct {
	Name        string        `json:"name"           bson:"name"`
	Description string        `json:"description"    bson:"description"`
	Address     string        `json:"address"        bson:"address"`
	StartTime   string        `json:"startTime"      bson:"startTime"`
	EndTime     string        `json:"endTime"        bson:"endTime"`
	Lat         float64       `json:"lat,string"     bson:"lat"`
	Lng         float64       `json:"lng,string"     bson:"lng"`
	Enabled     bool          `json:"enabled,string" bson:"enabled"`
	RouteID     string        `json:"routeId"        bson:"routeId"`
}

// RoutesHandler finds all of the routes in the database
func (App *App) RoutesHandler(w http.ResponseWriter, r *http.Request) {
	// Find all routes in database
	var routes []Route
	err := App.Routes.Find(bson.M{}).All(&routes)
	// Handle query errors
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
	// Send each route to client as JSON
	WriteJSON(w, routes)
}

// StopsHandler finds all of the route stops in the database
func (App *App) StopsHandler(w http.ResponseWriter, r *http.Request) {
	// Find all stops in database
	var stops []Stop
	err := App.Stops.Find(bson.M{}).All(&stops)
	// Handle query errors 
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
	// Send each stop to client as JSON
	WriteJSON(w, stops)
}

// RoutesCreateHandler adds a new route to the database
func (App *App) RoutesCreateHandler(w http.ResponseWriter, r *http.Request) {
	// Create a new route object using request fields
	route := Route{}
	err := json.NewDecoder(r.Body).Decode(&route)
	// Error handling
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)<commit_msg>gofmt<commit_after>package tracking

import (
	"encoding/json"
	"net/http"
	"time"

	"gopkg.in/mgo.v2/bson"
)

// Route represents a set of coordinates to draw a path on our tracking map
type Route struct {
	Id          bson.ObjectId `json:"id"             bson:"_id,omitempty"`
	Name        string        `json:"name"           bson:"name"`
	Description string        `json:"description"    bson:"description"`
	StartTime   string        `json:"startTime"      bson:"startTime"`
	EndTime     string        `json:"endTime"        bson:"endTime"`
	Enabled     bool          `json:"enabled,string" bson:"enabled"`
	Color       string        `json:"color"          bson:"color"`
	Width       int           `json:"width,string"   bson:"width"`
	Coords      string        `json:"coords"         bson:"coords"`
	Created     time.Time     `json:"created"        bson:"created"`
	Updated     time.Time     `json:"updated"        bson:"updated"`
}

// Stop indicates where a tracked object is scheduled to arrive
type Stop struct {
	Name        string  `json:"name"           bson:"name"`
	Description string  `json:"description"    bson:"description"`
	Address     string  `json:"address"        bson:"address"`
	StartTime   string  `json:"startTime"      bson:"startTime"`
	EndTime     string  `json:"endTime"        bson:"endTime"`
	Lat         float64 `json:"lat,string"     bson:"lat"`
	Lng         float64 `json:"lng,string"     bson:"lng"`
	Enabled     bool    `json:"enabled,string" bson:"enabled"`
	RouteID     string  `json:"routeId"        bson:"routeId"`
}

// RoutesHandler finds all of the routes in the database
func (App *App) RoutesHandler(w http.ResponseWriter, r *http.Request) {
	// Find all routes in database
	var routes []Route
	err := App.Routes.Find(bson.M{}).All(&routes)
	// Handle query errors
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
	// Send each route to client as JSON
	WriteJSON(w, routes)
}

// StopsHandler finds all of the route stops in the database
func (App *App) StopsHandler(w http.ResponseWriter, r *http.Request) {
	// Find all stops in database
	var stops []Stop
	err := App.Stops.Find(bson.M{}).All(&stops)
	// Handle query errors
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
	// Send each stop to client as JSON
	WriteJSON(w, stops)
}

// RoutesCreateHandler adds a new route to the database
func (App *App) RoutesCreateHandler(w http.ResponseWriter, r *http.Request) {
	// Create a new route object using request fields
	route := Route{}
	err := json.NewDecoder(r.Body).Decode(&route)
	// Error handling
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
{'fraction_non_alphanumeric': 0.12396845772969008, 'fraction_numerical': 0.0018338529249954153, 'mean_word_length': 2.840845070422535, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5960220', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1681, 'n_words': 481}