Skip to content

Commit

Permalink
merge conflict resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhiitbh committed Mar 3, 2019
2 parents df83108 + c96b1f1 commit f8d942c
Show file tree
Hide file tree
Showing 9 changed files with 910 additions and 222 deletions.
25 changes: 10 additions & 15 deletions JioKisan/AssignDelivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initializeMappingList(num_drivers, num_consignments, drivers, consignments):
entryType = 'Driver'
pk = drivers[i].pk
address = str(drivers[i].position_latitude)+','+str(drivers[i].position_longitude)
weight = drivers[i].vehicle_capacity
weight = drivers[i].truckCapacity
else:
k=i-num_drivers
consignmentEntry_index = int(k/2)
Expand All @@ -42,7 +42,7 @@ def initializeMappingList(num_drivers, num_consignments, drivers, consignments):
dropLongitude = consignmentObject.req.mandi_info.position_longitude
address = str(dropLatitude) + ',' + str(dropLongitude)

weight = consignments[consignmentEntry_index].prod.amount
weight = consignments[consignmentEntry_index].weight

infoDict = {
'entryType' : entryType,
Expand Down Expand Up @@ -194,22 +194,18 @@ def getConsignments():

def updateDatabase(assignedDriver, pathOfDriver, assignedConsignments):
# Now we have to change hired status of driver and status of consignments and add path to driver
# Syntax of path : farmEntity?status>purpose:pk of consignment;latitude,logitude|status>purpose:pk of consignment;latitude,logitude|...
# Syntax of path : purpose:pk of consignment;latitude,logitude|purpose:pk of consignment;latitude,logitude|...
path = ''
flag=0
for location in pathOfDriver:
if flag==1:
path=path+'|'

pk = location['pk']
path = path + Delivery.objects.get(pk=pk).req.FE_info.name + '?' + 'Not Reached' + '>'
path = path + str(location['entryType']) + ':' + str(location['pk']) + ';'
path = path + location['address']
path = path + location['entryType'] + ':' + location['pk'] + ';'
path = path + location['latitude']+','+location['longitude']
flag = 1

assignedDriverObject = Driver.objects.get(pk = assignedDriver['pk'])
assignedDriverObject.path = path
print('Pan in Assign Delivery : ', assignedDriverObject.PAN)
assignedDriverObject.isHired = True
assignedDriverObject.save()

Expand All @@ -225,27 +221,26 @@ def updateDatabase(assignedDriver, pathOfDriver, assignedConsignments):

def mapConsignments(mDict):

print('I AM IN MAPCONSIGNMENTS')
# Consignments which are pending
drivers = getDrivers(mDict)
consignments = getConsignments()
num_drivers = drivers.count()
num_consignments = consignments.count()

print('NUmber Drivers', num_drivers)
print('Number Consignment', num_consignments)
# print('NUmber Drivers', num_drivers)
# print('Number Consignment', num_consignments)
# A list of dicts map indices of driver/pickup/drop

while( (num_drivers>0) and (num_consignments>0) ):
# print('inside while')
mappingList = initializeMappingList(num_drivers, num_consignments, drivers, consignments)
# print('got mapping list')
assignedDriver , pathOfDriver, assignedConsignments = driverDeliveryAssignment(mappingList, num_drivers, num_consignments)
print('Assigne Driver')
# print('Assigne Driver')

updateDatabase(assignedDriver, pathOfDriver, assignedConsignments)
print('inside while lol')
drivers = getDrivers(mDict)

drivers = getDrivers()
consignments = getConsignments()
num_drivers = drivers.count()
num_consignments = consignments.count()
Expand Down
50 changes: 6 additions & 44 deletions JioKisan/JioKisan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
4: "farm_tool_sellers"
}
VEHICLE_MODELS= {
0:'AC',
1:'NON AC'
1:'AC',
2:'NON AC'
}
MEASUREMENT_TYPES = {
1:'KG',
Expand Down Expand Up @@ -48,8 +48,8 @@ class User_reg(models.Model):
GST_number=models.CharField(max_length=20,default=None, blank=True, null=True)
#only for truck driver
isHired=models.BooleanField(default=None, blank=True, null=True)
# Syntax of path : farmEntity?status>purpose:pk of consignment;latitude,logitude|status>purpose:pk of consignment;latitude,logitude|...
path=models.TextField(default=None, blank=True, null=True)
#Syntax of path: purpose:pk of consignment;latitude,logitude|purpose:pk of consignment;latitude,logitude|...
path=models.CharField(max_length=300,default=None, blank=True, null=True)
available_capacity=models.IntegerField(default=None, blank=True, null=True)
current_address=models.CharField(max_length=40,default=None, blank=True, null=True)
#only for truck driver
Expand Down Expand Up @@ -160,7 +160,7 @@ def RegisterUser(mdict):
if nu.role==1:# is Farmer
pass
elif nu.role==2:
nu.vehicle_model=(int(mdict['vehicle_model'])%2)
nu.vehicle_model=int(mdict['vehicle_model'])
nu.vehicle_capacity=int(mdict['vehicle_capacity'])
nu.vehicle_number=mdict['vehicle_number']
nu.licence_number=mdict['licence_number']
Expand Down Expand Up @@ -228,7 +228,6 @@ def LoginUser(mdict):
print ('fail exception occured')
return 'failure'


def VerifyLogin(mdict):
client = base.Client(('localhost', 11211))
otp_sent=client.get(mdict['phone_number'])
Expand Down Expand Up @@ -466,7 +465,7 @@ def list_produce(mdict):
print(produce_list)
return produce_list

def list_ftool():## for farmers dashboard
def list_ftool():
tool_entities=FarmEntity.objects.filter(isFarmTool=True)
tool_list=[]
for tools in tool_entities:
Expand All @@ -478,40 +477,3 @@ def list_ftool():## for farmers dashboard
tool_list.append(t_dict)
print(tool_list)
return tool_list

def list_past_consignment(mdict):
usr=User_reg.objects.get(PAN=mdict['PAN'])
if usr.role == 1:
requests=Request.objects.filter(mandi_info=usr)
produces=Produce.objects.filter(farmer_info=usr)
cons_list=[]
for req in requests:
if Consignment.objects.filter(req=req).count() > 0 :
cons1=Consignment.objects.get(req=req)
c_dict=model_to_dict(cons1)
c_dict['cons_type']='Buying From'
c_dict['sec_party']=cons1.prod.farmer_info.name
c_dict['entity_type']=cons1.prod.FE_info.name
cons_list.append(c_dict)
for prod in produces:
if Consignment.objects.filter(prod=prod).count() > 0 :
cons2=Consignment.objects.get(prod=prod)
c_dict=model_to_dict(cons2)
c_dict['cons_type']='Selling to'
c_dict['sec_party']=cons2.req.mandi_info.name
c_dict['entity_type']=cons2.req.FE_info.name
cons_list.append(c_dict)
return cons_list
usr=User_reg.objects.get(PAN=mdict['PAN'])

if usr.role == 4: # in case of ft sellers
produces=Produce.objects.filter(farmer_info=usr)
cons_list=[]
for prod in produces:
if Consignment.objects.filter(prod=prod).count() > 0 :
cons2=Consignment.objects.get(prod=prod)
c_dict=model_to_dict(cons2)
c_dict['farmer_name']=cons2.req.mandi_info.name
c_dict['entity_type']=cons2.req.FE_info.name
cons_list.append(c_dict)
return cons_list
2 changes: 1 addition & 1 deletion JioKisan/JioKisan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['10.3.5.231','0.0.0.0','192.168.43.229','127.0.0.1', '172.29.12.159', '172.29.9.16','172.29.10.189']
ALLOWED_HOSTS = ['10.3.5.231','0.0.0.0','192.168.43.229','127.0.0.1']
#ALLOWED_HOSTS = []


Expand Down
27 changes: 2 additions & 25 deletions JioKisan/JioKisan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,8 @@ def getDriverPath(request):
if request.method == 'POST':
data_rec = json.loads(request.body)
mDict = create_dict(data_rec)
print('Hai hai mDict \n\n', mDict)
path = getPath(mDict)
json_path = JsonResponse(path, safe=False)
json_path['Access-Control-Allow-Origin'] = '*'
json_path = JsonResponse(path)

return json_path

Expand Down Expand Up @@ -272,17 +270,6 @@ def addFTStoFConsignment(request):
print(response)
return response

@csrf_exempt
def getPastConsignment(request):
data_rec = []
if request.method == 'POST':
data_rec = json.loads(request.body)
diction = create_dict(data_rec)
print(diction)
response = JsonResponse(list_past_consignment(diction),safe=False)
response['Access-Control-Allow-Origin'] = '*'
print(response)
return response

@csrf_exempt
def list_farmTool(request):
Expand Down Expand Up @@ -343,18 +330,8 @@ def getHired(request):
mDict = create_dict(data_rec)
user = User_reg.objects.get(PAN=mDict['PAN'])
if user.role==2 and user.isHired == False :
print('Hai Hai Hai \n\n')
mapConsignments(mDict)
print('LOl lol lol \n\n')

return getDriverPath(request)


def updateDeliveryStatus(request):
data_rec =[]
if request.method == 'POST':
data_rec = json.loads(request.body)
mDict = create_dict(data_rec)
print("Printing mDIct : \n\n")
print(mDict)
print('\n\n')

37 changes: 10 additions & 27 deletions JioKisan/populateJioKIsanModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,17 @@ def randomString(stringLength=10):
randomString = randomString.upper()[0:stringLength] # convert it in a uppercase letter and trim to your size.
return randomString

def randomPhoneNumber(stringLength=10):
lettersAndDigits = string.digits
return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))


def populateUser_reg(N=5):
for entry in range(N):
name = fakegen.name()
phone_number = '+91'+ randomPhoneNumber()
phone_number = fakegen.phone_number()
role = random.randint(1,4)
location = fakegen.local_latlng(country_code="IN", coords_only=False)
address = location[2]
PAN = randomString(17)
licence_number = randomString()
vehicle_number = fakegen.license_plate()
vehicle_model = random.randint(0,1)
vehicle_model = random.randint(1,2)
vehicle_capacity = random.randint(400,2000)
organisation_name = fakegen.company()
bank_account_number= randomString(13)
Expand Down Expand Up @@ -121,30 +116,19 @@ def populateConsignments(N=5):
random_farm_entity = farm_entities[random.randint(0,farm_entities_count-1)]
produces = Produce.objects.all().filter(FE_info = random_farm_entity, isAssigned=False)
produces_count = produces.count()
random_prod_index = random.randint(0,produces_count-1)
random_prod_index = random.randint(0,produces_count-1)
produce = produces[random_prod_index]
requests = Request.objects.all().filter(FE_info = random_farm_entity, isAssigned=False)
requests_count = requests.count()
random_req_index = random.randint(0,requests_count-1)

# print('produces_count', produces_count)
# print('random_prod_index', random_prod_index)
# print('requests_count', requests_count)
# print('random_req_index', random_req_index)

random_req_index = random.randint(0, random_req_index-1)
request = requests[random_req_index]

if produces_count>0 and requests_count > 0 :
produce = produces[random_prod_index]
request = requests[random_req_index]
cost, expected_delivery = getDeliveryInfo(request, produce)

consignment = Consignment.objects.get_or_create(req=request, prod=produce,
expected_delivery=expected_delivery,
cost = cost)

request.isAssigned = True
request.save()
produce.isAssigned = True
produce.save()







Expand All @@ -153,6 +137,5 @@ def populateConsignments(N=5):
populateUser_reg(30)
populateProduce(15)
populateRequest(15)
populateConsignments(7)


Loading

0 comments on commit f8d942c

Please sign in to comment.