Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
func Migrate() error
Migrate will attempt to create all tables defined by models. And return an error if one occurs, nil otherwise.
func StringParseErrors ¶
func StringParseErrors(errs []ParseError) []string
StringParseErrors converts a slice of Parse Errors to a slice of strings
Types ¶
type Crime ¶
type Crime struct { // ID is a unique identifier ID int // ReportID is the unique identifier of the Report the crime was parsed // from ReportID int // Page indicates which page of the report a crime was reported on Page int // DateReported records when the criminal activity was disclosed to the // police DateReported time.Time // DateOccurredStart records when the criminal activity started taking // place DateOccurredStart time.Time // DateOccurredEnd records when the criminal activity stopped taking // place DateOccurredEnd time.Time // ReportSuperID is the first portion of police report ID associated // with the reported crime. ReportSuperID uint // ReportSubID is the second portion of the police report ID associated // with the reported crime ReportSubID uint // GeoLocID is the unique ID of the Geo entry which holds the geographically // encoded location in lat long form GeoLocID int // Incidents holds the official classifications of the criminal // activity which took place Incidents pq.StringArray `gorm:"type:text[]"` // Descriptions holds any details about the specific incidents which // took place Descriptions pq.StringArray `gorm:"type:text[]"` // Remediation is the action taken by the institution who reported the // crime to deal with the criminal activity Remediation string // ParseErrors holds any errors that occur while parsing the crime. // These will be saved in other db tables depending on their types. // // This field is used internally only. Not serialized and sent as // part of any API responses. ParseErrors []ParseError `json:"-"` }
Crime structs hold information about criminal activity reported by Clery act reports
func NewCrime ¶
NewCrime creates a new Crime model from a database query sql.Rows result set. This query should select the id, report_id, page, university, date_reported, date_occurred, report_super_id, report_sub_id, geo_loc_id, incidents, descriptions, and remediations fields.
An Crime instance and error is returned. Nil on success.
func QueryAllCrimes ¶
func QueryAllCrimes(offset uint, limit uint, orderBy OrderByType) ([]*Crime, error)
QueryAllCrimes retrieves the specified number of Crime models from the database. Ordered by the field specified in the orderBy argument. Must be one of 'date_reported' or 'date_occurred'. An array of Crimes are returned, along with an error. Which is nil on success.
Retrieves all crime columns.
func (*Crime) Insert ¶
Insert adds the model to the database and sets the Crime.ID field to the newly inserted models ID. Additionally an error is returned if one occurs, or nil on success.
func (*Crime) InsertIfNew ¶
InsertIfNew saves the current Crime model if it does not exist in the db. Returns an error if one occurs, or nil on success.
type GeoBound ¶
type GeoBound struct { // ID is the unique identifier ID int // NeLat holds the latitude which the northeast corner of the map // viewport should be located at NeLat float64 // NeLong holds the longitude which the northeast corner of the map // viewport should be located at NeLong float64 // SwLat holds the latitude which the southwest corner of the map // viewport should be located at SwLat float64 // SwLong holds the longitude which the southwest corner of the map // viewport should be located at SwLong float64 }
GeoBound indicates a square area on a map
func GeoBoundFromMapsBound ¶
func GeoBoundFromMapsBound(bounds maps.LatLngBounds) *GeoBound
GeoBoundFromMapsBound creates a new GeoBound instance from a Google Maps API maps.LatLngBounds structure
func (*GeoBound) Insert ¶
Insert adds a GeoBound model to the database. An error is returned if one occurs, nil on success.
func (*GeoBound) InsertIfNew ¶
InsertIfNew attempts to find a GeoBound model with the same values in the database. If none is found, the model is added to the database. In both cases the GeoBound.ID field is set to that of the found/inserted row in the db. An error is returned if one occurs, or nil on success.
type GeoLoc ¶
type GeoLoc struct { // ID is the unique identifier ID int // Located indicates if the raw location has been geocoded using the // GAPI Located bool // GAPISuccess indicates if the GAPI locate request succeeded GAPISuccess bool // Lat is the latitude of the location Lat float64 // Long is the longitude of the location Long float64 // PostalAddr holds the formatted postal address of the location PostalAddr string // Accuracy indicates how close to the provided location the lat long // are Accuracy GeoLocAccuracy // BoundsProvided indicates whether any location bounds were provided BoundsProvided bool // BoundsID holds the GeoBounds ID which specifies the location of the // crime BoundsID sql.NullInt64 // ViewportBoundsID holds the GeoBounds ID which specifies the // recommended viewport for looking at the crime location ViewportBoundsID int // GAPIPlaceID holds the GAPI location ID, used to retrieve additional // information about a location using the GAPI GAPIPlaceID string // Raw holds the text present on the crime report which the GeoLoc // attempts to locate Raw string }
GeoLoc holds information about the geographical location of a crime "location" field.
GeoLoc are resolved by using the Google Geocoding API to transform location strings into lat long coords. GeoLoc also holds some additional accuracy information, as not all locations can be resolved exactly.
func NewUnlocatedGeoLoc ¶
NewUnlocatedGeoLoc creates a new GeoLoc instance from the currently selected result set in the provided sql.Rows object. This row should select the id and raw fields, in that order. An error will be returned if one occurs, nil on success.
func QueryUnlocatedGeoLocs ¶
QueryUnlocatedGeoLocs finds all GeoLoc models which have not been located on a map. Additionally an error is returned if one occurs, or nil on success.
func (*GeoLoc) Insert ¶
Insert adds a GeoLoc model to the database. An error is returned if one occurs, or nil on success.
func (*GeoLoc) Query ¶
Query attempts to find a GeoLoc model in the db with the same raw field value. If a model is found, the GeoLoc.ID field is set. Additionally an error is returned if one occurs. sql.ErrNoRows is returned if no GeoLocs were found. Or nil on success.
func (GeoLoc) Update ¶
Update sets an existing GeoLoc model's fields to new values. Only updates the located and raw fields if located == false. Updates all fields if located == true.
It relies on the raw field to specify exactly which row to update. The row column has a unique constraint, so this is sufficient.
An error is returned if one occurs, or nil on success.
type GeoLocAccuracy ¶
type GeoLocAccuracy string
const ( // AccuracyPerfect indicates that the location provided by the GAPI // is exact AccuracyPerfect GeoLocAccuracy = "ROOFTOP" // AccuracyBetween indicates that the location provided by the GAPI // is between two addresses AccuracyBetween GeoLocAccuracy = "RANGE_INTERPOLATED" // AccuracyCenter indicates that the location is in the middle of an // region. Such as a block AccuracyCenter GeoLocAccuracy = "GEOMETRIC_CENTER" // AccuracyApprox indicates that the location is not exact AccuracyApprox GeoLocAccuracy = "APPROXIMATE" // AccuracyErr indicates that an invalid string value was provided // when creating a GeoLocAccuracy AccuracyErr GeoLocAccuracy = "ERR" )
func NewGeoLocAccuracy ¶
func NewGeoLocAccuracy(str string) (GeoLocAccuracy, error)
type OrderByType ¶
type OrderByType string
OrderByType is the type alias used to represent the field used to order rows by in the QueryAll method
const ( // OrderByReported indicates that the QueryAll function should order // results by the date_reported field OrderByReported OrderByType = "date_reported" // OrderByOccurred indicates that the QueryAll function should order // results by the date_occurred field OrderByOccurred OrderByType = "date_occurred" // OrderByErr indicates that the created OrderByType had an invalid // string value OrderByErr OrderByType = "invalid" )
func NewOrderByType ¶
func NewOrderByType(val string) (OrderByType, error)
NewOrderByType creates an OrderByType with the specified string value. An error is returned if the provided string value is not a valid OrderByType. Or nil on success.
type ParseError ¶
type ParseError struct { // ID is the unique identifier of the parse error ID int // CrimeID is ID of the Crime which the parse error refers to CrimeID int // Field holds the name of the crime field which was corrected Field string // Original holds the value of the field before it was corrected Original string // Corrected holds the value of the field after it was corrected Corrected string // ErrType holds a computer identifiable value for the error that // occurred ErrType ParseErrorType }
ParseError structs holds details about errors which occur while parsing crimes from reports. And the actions that take place to fix them.
This information is recorded just in case the crime was fixed incorrectly.
func (*ParseError) Insert ¶
func (e *ParseError) Insert() error
Insert adds a ParseError model to the database. An error is returned if one occurs, or nil on success.
The ParseError.ID field will be set to record the ID of the newly inserted row.
func (*ParseError) InsertIfNew ¶
func (e *ParseError) InsertIfNew() error
InsertIfNew will add a ParseError to the database if one with the same values doesn't already exist. The found / inserted row's ID will be recorded in the ParseError.ID field.
An error will be returned if one occurs, or nil on success
func (*ParseError) Query ¶
func (e *ParseError) Query() error
Query searches for a parse error with the same field values in the database. An error is returned if one occurs, or nil on success.
The ParseError.ID field will be set to record the ID of the row in the database.
func (ParseError) String ¶
func (e ParseError) String() string
String converts a ParseError into a string
type ParseErrorType ¶
type ParseErrorType string
ParseErrorType is an alias for the string type, which is used to represent ErrTypes
const ( // TypeBadRangeEnd signifies that a Crime's date range's end date // occurred before a range's start date. TypeBadRangeEnd ParseErrorType = "BAD_RANGE_END" )
type Report ¶
type Report struct { // ID is the unique report identifier ID int // ParsedOn indicates the date and time the report was processed ParsedOn *time.Time // ParseSuccess indicates if the report was successfully parsed ParseSuccess bool // University indicates which institution published the crime report // document University UniversityType // RangeStartDate indicates the start of the date range crimes were reported // for RangeStartDate *time.Time // RangeEndDate indicates the end of the date range crimes were reported // for RangeEndDate *time.Time // Pages holds the number of pages the document had Pages uint // CrimesCount holds the number of crimes parsed from the report CrimesCount uint }
Report holds information about documents parsed by crime-map to extract Crime models. These documents are typically published as an obligation to the Clery Act. And hold multiple individual crime reports.
func NewReport ¶
func NewReport(univ UniversityType, parsedOn *time.Time, start *time.Time, end *time.Time, pages uint) *Report
NewReport will create a new Report model.
func NewReportFromRow ¶
NewReportFromRow creates a new Report model from a database row. This row should be from a query which selects the id, parsed_on, parse_success, university, covers_range, pages and crimes_count fields. Additionally an error is returned if one occurs, nil on success.
func QueryAllReports ¶
QueryAllReports finds all Report models from the database. And returns them with their Report.ID fields populated. Additionally an error is returned if one occurs. Nil on success.
func (*Report) Insert ¶
Insert adds a Report model to the database. An error is returned if one occurs, or nil on success.
The ID of the newly inserted row will be saved in the Report.ID field.
func (*Report) InsertIfNew ¶
InsertIfNew adds a Report model to the database if one with existing values does not exist yet. The ID of the queried/inserted row is saved in the Report.ID field. An error is returned if one occurs, nil on success.
func (*Report) Query ¶
Query attempts to find a Report with the same parse_success, university, covers_range, and pages field values. The parsed_on, parse_success, and crimes_count fields are left out of the query.
It populates the Report.ID and Report.ParseSucces fields with the database row. An error is returned if one occurs, or nil on success.
func (Report) UpdatePostParseFields ¶
UpdatePostParseFields updates the parse_success and crimes_count fields for the database row with a matching Report.ID field.
These 2 fields are updated after a report has been parsed. As their values can only be know after all crimes have been extracted.
type UniversityType ¶
type UniversityType string
UniversityType is a string type alias, used to represent the valid university's a report can be published from.
const ( // UniversityDrexel indicates that a report was published by Drexel UniversityDrexel UniversityType = "Drexel University" // UniversityErr indicates that a report was provided with an invalid // value UniversityErr UniversityType = "Err" )
func NewUniversityType ¶
func NewUniversityType(raw string) (UniversityType, error)
NewUniversityType constructs a new valid UniversityType from a raw string. An error is returned if one occurs, or nil on success.