Exemple #1
0
    def setRestCounters(self):
        rules = App.getCR(App)
        period = rules.periodCounter
        totalPoints = 0
        for user in User.objects.all():
            totalPoints = period + totalPoints

        for rest in Restaurant.objects.filter(serviceStatus=True):
            points = Points.objects.filter(restaurant=rest)
            for point in points:
                serviceCounter = (point.point / totalPoints) * 100
                intServiceCounter = int(serviceCounter)
                if rest.serviceCounter == 0:
                    rest.serviceCounter = intServiceCounter
                    rest.save()

        Restaurant.serviceCounters(Restaurant)
        rules.save()
Exemple #2
0
    def updateRestStatus(self, newStatus, upRestName):
        rules = App.getCR(App)
        upRestaurant = self.objects.get(restName=upRestName)
        if rules.calculationCheck == True:
            if newStatus == False:
                activeCounter = self.objects.filter(
                    serviceCounter__gt=0, serviceStatus=True).count()
                counter = upRestaurant.serviceCounter
                if activeCounter != 0 and counter != 0:
                    for activeRest in self.objects.filter(
                            serviceCounter__gt=0,
                            serviceStatus=True).order_by('-serviceCounter'):
                        activeRest.serviceCounter = activeRest.serviceCounter + 1
                        activeRest.save()
                        counter = counter - 1
                        if counter == 0:
                            break
                else:
                    return False

            else:
                activeRests = self.objects.filter(serviceCounter__gt=0,
                                                  serviceStatus=True)
                activeCounter = self.objects.filter(
                    serviceCounter__gt=0, serviceStatus=True).count()

                counter = upRestaurant.serviceCounter
                if activeCounter != 0 and counter != 0:
                    for activeRest in self.objects.filter(
                            serviceCounter__gt=0,
                            serviceStatus=True).order_by('-serviceCounter'):
                        if activeRest.serviceCounter > 0:
                            activeRest.serviceCounter = activeRest.serviceCounter - 1
                            activeRest.save()
                            counter = counter - 1
                        if counter == 0:
                            break

                else:
                    return False

        upRestaurant.serviceStatus = newStatus
        upRestaurant.save()
        return True
Exemple #3
0
def statistics(request):
    rules = App.getCR(App)
    restList = []
    counter = 1
    userCount = User.objects.all().count()
    totalPoints = rules.calculationPeriod * userCount
    total =  Restaurant.objects.all().count()
    vehicleCount = Restaurant.objects.filter(modeOfTransport = True).count()
    pedestrianCount = Restaurant.objects.filter(modeOfTransport = True).count()
    aviableInBadWeather = Restaurant.objects.filter(weatherCondition = True).count()
    AnaviableInBadWeather = Restaurant.objects.filter(weatherCondition = False).count()
    activeRests = Restaurant.objects.filter(serviceStatus = True).count()
    inactiveRests = Restaurant.objects.filter(serviceStatus = False).count()
    infoList = [{'userCount':userCount,'totalPoints':totalPoints,'totalRests':total,'vehicleRests':vehicleCount,'pedestrianRests':pedestrianCount,'aviableInBadWeather':aviableInBadWeather,'AnaviableInBadWeather':AnaviableInBadWeather,'activeRests':activeRests,'inactiveRests':inactiveRests}]
    allCalculations = Calculation.objects.all().count()
    restNames = []
    restFlag = False
    for record in Calculation.objects.all():
                restFlag = False
                for restName in restNames:
                    if record.restaurant.restName == restName:
                        restFlag = True
                        break
                if restFlag == True:
                    continue
                restNames.append(record.restaurant.restName)
                restObject = Restaurant.objects.get(restName = record.restaurant.restName )
                rest = Calculation.objects.filter(restaurant = restObject).count()
                restPoint = Points.objects.filter(restaurant = restObject)
                finalPoint = 0
                for point in restPoint:
                    finalPoint = finalPoint+point.point
                row = {'restName':record.restaurant.restName,'wentCount':rest,'point' : finalPoint,'serviceCounter':restObject.serviceCounter,'modeOfTransport':restObject.modeOfTransport,'weatherCondition':restObject.weatherCondition,'serviceStatus':restObject.serviceStatus}
                restList.append(row)
                
    context = Context({'app':rules,'Calculation' : restList,'infoList':infoList})
    return render(request,'statistics.html',context)
        
    
Exemple #4
0
    def serviceCounters(self):
        rules = App.getCR(App)
        counter = rules.periodCounter
        for rest in Restaurant.objects.filter(serviceStatus=True):
            counter = counter - rest.serviceCounter
        while counter > 0:
            for rest in Restaurant.objects.filter(
                    serviceStatus=True).order_by('-serviceCounter'):
                rest.serviceCounter = rest.serviceCounter + 1
                rest.save()
                counter = counter - 1
                if counter == 0:
                    break
        while counter < 0:
            for rest in Restaurant.objects.filter(
                    serviceStatus=True).order_by('serviceCounter'):
                if rest.serviceCounter > 1:
                    rest.serviceCounter = rest.serviceCounter - 1
                    rest.save()
                    counter = counter + 1
                if counter == 0:
                    break

        vehicleRestaurants = Restaurant.objects.filter(modeOfTransport=True,
                                                       serviceStatus=True,
                                                       weatherCondition=True)
        vrestCounter = 0
        for vrest in vehicleRestaurants:
            vrestCounter = vrest.serviceCounter + vrestCounter

        constantIstanbul = [
            17.5, 15.3, 13.8, 10.4, 8.1, 6.1, 4.2, 4.9, 7.4, 11.3, 13.2, 17.2
        ]
        currentDate = datetime.datetime.now()
        currentDay = currentDate.day
        totalDays = rules.periodCounter
        totalMonthsFloat = totalDays / 30
        totalMonthsRound = math.ceil(totalMonthsFloat)
        badWeatherProbability = (
            (30 - currentDay) * constantIstanbul[currentDate.month - 1]) / 30
        for i in range(1, totalMonthsRound):
            if (i - totalMonthsFloat + 1) > 0:
                badWeatherProbability = (
                    30 * (i - totalMonthsFloat) *
                    constantIstanbul[currentDate.month - 1 +
                                     i]) / 30 + badWeatherProbability
            badWeatherProbability = constantIstanbul[currentDate.month - 1 +
                                                     i] + badWeatherProbability

        if vrestCounter < int((rules.periodCounter / badWeatherProbability)):

            transporBalanceCounter = int(
                (rules.periodCounter / badWeatherProbability)) - vrestCounter
            counter = transporBalanceCounter
            while transporBalanceCounter > 0:
                for rest in Restaurant.objects.filter(
                        modeOfTransport=False,
                        serviceStatus=True,
                        weatherCondition=False).order_by('serviceCounter'):
                    rest.serviceCounter = rest.serviceCounter - 1
                    rest.save()
                    counter = counter - 1
                    if counter == 0:
                        break

                for rest in vehicleRestaurants.order_by('-serviceCounter'):
                    rest.serviceCounter = rest.serviceCounter + 1
                    rest.save()
                    transporBalanceCounter = transporBalanceCounter - 1
                    if transporBalanceCounter == 0:
                        break