func (cdb ComplaintDB) AddHistoricalComplaintByEmailAddress(ea string, c *types.Complaint) error { var cp *types.ComplainerProfile var err error cp, err = cdb.GetProfileByEmailAddress(ea) if err != nil { return err } c.Profile = *cp key := datastore.NewIncompleteKey(cdb.Ctx(), kComplaintKind, cdb.emailToRootKey(cp.EmailAddress)) _, err = datastore.Put(cdb.Ctx(), key, c) return err }
func (cdb ComplaintDB) complainByProfile(cp types.ComplainerProfile, c *types.Complaint) error { client := urlfetch.Client(cdb.C) fr := fr24.Fr24{Client: client} overhead := fr24.Aircraft{} //cdb.C.Infof("adding complaint for [%s] %s", cp.CallerCode, overhead.FlightNumber) // abw hack hack grabAnything := (cp.CallerCode == "QWERTY") c.Debug, _ = fr.FindOverhead(geo.Latlong{cp.Lat, cp.Long}, &overhead, grabAnything) if overhead.Id != "" { c.AircraftOverhead = overhead } c.Version = kComplaintVersion c.Profile = cp // Copy the profile fields into every complaint // Too much like the last complaint by this user ? Just update that one. if prev, err := cdb.GetNewestComplaintByEmailAddress(cp.EmailAddress); err != nil { cdb.C.Errorf("complainByProfile/GetNewest: %v", err) } else if prev != nil && ComplaintsAreEquivalent(*prev, *c) { // The two complaints are in fact one complaint. Overwrite the old one with data from new one. Overwrite(prev, c) return cdb.UpdateComplaint(*prev, cp.EmailAddress) } key := datastore.NewIncompleteKey(cdb.C, kComplaintKind, cdb.emailToRootKey(cp.EmailAddress)) _, err := datastore.Put(cdb.C, key, c) // TEMP /* if debug,err := bksv.PostComplaint(client, cp, *c); err != nil { cdb.C.Infof("BKSV Debug\n------\n%s\n------\n", debug) cdb.C.Infof("BKSV posting error: %v", err) } else { cdb.C.Infof("BKSV Debug\n------\n%s\n------\n", debug) } */ return err }
func (cdb ComplaintDB) complainByProfile(cp types.ComplainerProfile, c *types.Complaint) error { client := cdb.HTTPClient() overhead := flightid.Aircraft{} // Check we're not over a daily cap for this user cdb.Debugf("cbe_010", "doing rate limit check") s, e := date.WindowForToday() if prevKeys, err := cdb.GetComplaintKeysInSpanByEmailAddress(s, e, cp.EmailAddress); err != nil { return err } else if len(prevKeys) >= KMaxComplaintsPerDay { return fmt.Errorf("Too many complaints filed today") } else { cdb.Debugf("cbe_011", "rate limit check passed (%d); calling FindOverhead", len(prevKeys)) } elev := 0.0 pos := geo.Latlong{cp.Lat, cp.Long} algo := flightid.AlgoConservativeNoCongestion if c.Description == "ANYANY" { algo = flightid.AlgoGrabClosest } if as, err := fr24.FetchAirspace(client, pos.Box(64, 64)); err != nil { cdb.Errorf("FindOverhead failed for %s: %v", cp.EmailAddress, err) } else { oh, deb := flightid.IdentifyOverhead(as, pos, elev, algo) c.Debug = deb if oh != nil { overhead = *oh c.AircraftOverhead = overhead } } cdb.Debugf("cbe_020", "FindOverhead returned") // Contrast with the skypi pathway if cp.CallerCode == "WOR004" || cp.CallerCode == "WOR005" { asFdb, _ := airspace.Fetch(client, "", pos.Box(60, 60)) oh3, deb3 := flightid.IdentifyOverhead(asFdb, pos, elev, algo) if oh3 == nil { oh3 = &flightid.Aircraft{} } newdebug := c.Debug + "\n*** v2 / fdb testing\n" + deb3 + "\n" headline := "" if overhead.FlightNumber != oh3.FlightNumber { headline = fmt.Sprintf("** * * DIFFERS * * **\n") } else { // Agree ! Copy over the Fdb IdSpec, and pretend we're living in the future headline = fmt.Sprintf("**---- Agrees ! ----**\n") c.AircraftOverhead.Id = oh3.Id } headline += fmt.Sprintf(" * skypi: %s\n * orig : %s\n", oh3, overhead) c.Debug = headline + newdebug } c.Version = kComplaintVersion // Kill this off ? c.Profile = cp // Copy the profile fields into every complaint // Too much like the last complaint by this user ? Just update that one. cdb.Debugf("cbe_030", "retrieving prev complaint") if prev, err := cdb.GetNewestComplaintByEmailAddress(cp.EmailAddress); err != nil { cdb.Errorf("complainByProfile/GetNewest: %v", err) } else if prev != nil && ComplaintsAreEquivalent(*prev, *c) { cdb.Debugf("cbe_031", "returned, equiv; about to UpdateComlaint()") // The two complaints are in fact one complaint. Overwrite the old one with data from new one. Overwrite(prev, c) err := cdb.UpdateComplaint(*prev, cp.EmailAddress) cdb.Debugf("cbe_032", "updated in place (all done)") return err } cdb.Debugf("cbe_033", "returned, distinct/first; about to put()") key := datastore.NewIncompleteKey(cdb.Ctx(), kComplaintKind, cdb.emailToRootKey(cp.EmailAddress)) _, err := datastore.Put(cdb.Ctx(), key, c) cdb.Debugf("cbe_034", "new entity added (all done)") // TEMP /* if debug,err := bksv.PostComplaint(client, cp, *c); err != nil { cdb.Infof("BKSV Debug\n------\n%s\n------\n", debug) cdb.Infof("BKSV posting error: %v", err) } else { cdb.Infof("BKSV Debug\n------\n%s\n------\n", debug) } */ return err }