Exemple #1
0
def getActiveRideOffersSortedAbitualiAndPerDay(percorso_passeggero):
    import route
    import params
    import date_time_util as dtu
    from datetime import timedelta

    nowWithTolerance = dtu.removeTimezone(dtu.nowCET()) - timedelta(minutes=params.TIME_TOLERANCE_MIN)

    percorsi_compatibili = route.getPercorsiCompatibili(percorso_passeggero)

    if percorsi_compatibili:
        qry_rides = RideOffer.query(
            ndb.AND(
                RideOffer.percorso.IN(percorsi_compatibili),
                RideOffer.active == True,
                ndb.OR(
                    RideOffer.programmato == True,
                    RideOffer.start_datetime >= nowWithTolerance
                )
            )
        )
        offers = qry_rides.fetch()
    else:
        offers = []
    return filterAndSortOffersAbitualiAndPerDay(offers) #abituali, perDay
Exemple #2
0
def getActiveRideOffersQry():
    import params
    import date_time_util as dtu
    from datetime import timedelta
    qry = RideOffer.query(
        ndb.AND(
            RideOffer.active == True,
            ndb.OR(
                RideOffer.programmato == True,
                RideOffer.start_datetime >= dtu.removeTimezone(dtu.nowCET()) -
                timedelta(minutes=params.TIME_TOLERANCE_MIN))))
    return qry
Exemple #3
0
 def getDepartingDateStr(self):
     import date_time_util as dtu
     import params
     date_str = dtu.formatDate(self.start_datetime)
     if date_str == dtu.formatDate(dtu.nowCET()):
         date_str += ' (OGGI)'
     elif date_str == dtu.formatDate(dtu.tomorrow()):
         date_str += ' (DOMANI)'
     elif self.programmato_giorni:  # PROX_GIORNI
         giorno_index = self.programmato_giorni[0]
         date_str += ' ({})'.format(params.GIORNI_SETTIMANA[giorno_index])
     return date_str
Exemple #4
0
def getActiveRideOffersDriver(driver_id):
    import params
    import date_time_util as dtu
    from datetime import timedelta
    now_with_tolerance = dtu.removeTimezone(
        dtu.nowCET()) - timedelta(minutes=params.TIME_TOLERANCE_MIN)
    qry = RideOffer.query(
        ndb.AND(
            RideOffer.active == True, RideOffer.driver_id == driver_id,
            ndb.OR(RideOffer.programmato == True,
                   RideOffer.start_datetime >= now_with_tolerance))).order(
                       RideOffer.start_datetime)
    return qry.fetch()
Exemple #5
0
    def getDescription(self, driver_info=True):
        import routing_util
        import params
        import date_time_util as dtu
        import person
        msg = []
        percorso = self.getPercorso()
        start_fermata, end_fermata = routing_util.decodePercorso(percorso)

        msg.append('*Partenza*: {}'.format(start_fermata))
        msg.append('*Arrivo*: {}'.format(end_fermata))

        if self.programmato:
            giorni = [
                params.GIORNI_SETTIMANA_FULL[i]
                for i in self.programmato_giorni
            ]
            giorni_str = ', '.join(giorni)
            msg.append('*Ora partenza*: {}'.format(self.getDepartingTime()))
            msg.append('*Tipologia*: {}'.format(self.getTimeMode()))
            msg.append('*Ogni*: {}'.format(giorni_str))
        else:
            msg.append('*Quando*: {}'.format(self.getTimeMode()))
            msg.append('*Ora partenza*: {}'.format(self.getDepartingTime()))
            date_str = dtu.formatDate(self.start_datetime)
            if date_str == dtu.formatDate(dtu.nowCET()):
                date_str += ' (OGGI)'
            elif date_str == dtu.formatDate(dtu.tomorrow()):
                date_str += ' (DOMANI)'
            elif self.programmato_giorni:  # PROX_GIORNI
                giorno_index = self.programmato_giorni[0]
                date_str += ' ({})'.format(
                    params.GIORNI_SETTIMANA[giorno_index])
            msg.append('*Giorno partenza*: {}'.format(date_str))
        if driver_info:
            username = person.getPersonById(
                self.driver_id).getUsername()  # self.driver_username
            if username is None:
                from main import tell_admin
                tell_admin(
                    '❗ viaggio con driver_id {} non ha più username'.format(
                        self.driver_id))
                username = '******'
            else:
                username = '******'.format(username)
            msg.append('*Autista*: {} {}'.format(self.getDriverName(),
                                                 username))
            avg_distance, avg_duration = self.getAvgDistanceDuration()
            msg.append('*Distanza*: {}'.format(avg_distance))
            msg.append('*Durata*: {}'.format(avg_duration))
        return '\n'.join(msg)
Exemple #6
0
def addRideOffer(driver, start_datetime, percorso, time_mode, programmato,
                 giorni):
    import date_time_util as dtu
    o = RideOffer(driver_id=driver.getId(),
                  driver_name_lastname=driver.getFirstNameLastName(),
                  driver_username=driver.getUsername(),
                  start_datetime=start_datetime,
                  percorso=percorso,
                  registration_datetime=dtu.removeTimezone(dtu.nowCET()),
                  active=True,
                  time_mode=time_mode,
                  programmato=programmato,
                  programmato_giorni=giorni)
    o.put()
    return o
Exemple #7
0
def getActiveRideOffers():
    import params
    import date_time_util as dtu
    from datetime import timedelta

    qry = RideOffer.query(
        ndb.AND(
            RideOffer.active == True,
            ndb.OR(
                RideOffer.programmato == True,
                RideOffer.start_datetime >= dtu.removeTimezone(dtu.nowCET()) -
                timedelta(minutes=params.TIME_TOLERANCE_MIN)
                # might be redundant as the filter is also applied afterwards
            )))
    offers = qry.fetch()
    return offers
Exemple #8
0
def filterAndSortOffersPerDay(offers):
    import params
    import date_time_util as dtu
    from datetime import timedelta

    result = [[], [], [], [], [], [], []]
    today = dtu.getWeekday()
    now_dt = dtu.removeTimezone(
        dtu.nowCET()) - timedelta(minutes=params.TIME_TOLERANCE_MIN)
    now_time = now_dt.time()
    for o in offers:
        if o.programmato:
            for g in o.programmato_giorni:
                # exclude those of today which have already happened
                if g != today or o.start_datetime.time(
                ) > now_time:  #o.programmato_time > now_time:
                    result[g].append(o)
        elif o.start_datetime > now_dt:
            g = dtu.getWeekday(o.start_datetime)
            result[g].append(o)
    for results_days in result:
        results_days.sort(key=lambda x: x.getDepartingTime())
    return result
Exemple #9
0
 def disactivate(self, put=True):
     import date_time_util as dtu
     self.active = False
     self.disactivation_datetime = dtu.removeTimezone(dtu.nowCET())
     if put:
         self.put()
Exemple #10
0
def getRideOfferInsertedLastDaysQry(days):
    import date_time_util as dtu
    from datetime import timedelta
    return RideOffer.query(
        RideOffer.start_datetime >= dtu.removeTimezone(dtu.nowCET()) -
        timedelta(days=days))
Exemple #11
0
def setMenuImageId(name, id, userinfo):
    m = getMensaByName(name)
    m.menu_image_id = id
    m.menu_image_last_update_datetime = dtu.nowCET()
    m.menu_image_last_update_userinfo = userinfo
    m.put()