Browse Source

connected

connected all the python files together
add-license-1
Yiğit Çolakoğlu 7 years ago
parent
commit
793d7304b1
7 changed files with 325 additions and 208 deletions
  1. +123
    -35
      Barcode_Reader_Python/.idea/workspace.xml
  2. BIN
      Barcode_Reader_Python/database_actions.pyc
  3. +66
    -54
      Barcode_Reader_Python/generate_moves.py
  4. BIN
      Barcode_Reader_Python/generate_moves.pyc
  5. +18
    -2
      Barcode_Reader_Python/main.py
  6. +118
    -117
      Barcode_Reader_Python/sort_date.py
  7. BIN
      Barcode_Reader_Python/sort_date.pyc

+ 123
- 35
Barcode_Reader_Python/.idea/workspace.xml View File

@ -2,25 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="7b5ef56c-2d3e-44d9-be69-b414f166f99b" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.gitkeep" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/Barcode_Reader_Python.iml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/arduino-i2c/arduino-i2c.ino" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/barcodes.csv" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/database_actions.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pi@192.168.1.25" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/raspberry_zbar.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/run.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/sort_calc_base_1hand.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/sort_calc_base_2handed.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/sort_date.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/zbar.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/zbar_live.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../FoodCloud.apk" beforeDir="false" afterPath="$PROJECT_DIR$/../FoodCloud.apk" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../get-pip.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/generate_moves.py" beforeDir="false" afterPath="$PROJECT_DIR$/generate_moves.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/sort_date.py" beforeDir="false" afterPath="$PROJECT_DIR$/sort_date.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
@ -31,12 +15,45 @@
</component>
<component name="CoverageDataManager">
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$RUN.coverage" NAME="RUN Coverage Results" MODIFIED="1529584815747" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$generate_moves.coverage" NAME="generate_moves Coverage Results" MODIFIED="1529614908540" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$raspberry_live.coverage" NAME="raspberry_live Coverage Results" MODIFIED="1529585357099" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$main.coverage" NAME="main Coverage Results" MODIFIED="1529587310168" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$sort_date.coverage" NAME="sort_date Coverage Results" MODIFIED="1529590504238" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$main.coverage" NAME="main Coverage Results" MODIFIED="1529615873965" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$Unnamed.coverage" NAME="raspberry_live Coverage Results" MODIFIED="1529543452123" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
<component name="FileEditorManager">
<leaf />
<leaf>
<file leaf-file-name="main.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285">
<caret line="75" lean-forward="true" selection-start-line="75" selection-end-line="75" />
<folding>
<element signature="e#32#69#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="generate_moves.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/generate_moves.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285">
<caret line="117" column="100" selection-start-line="117" selection-start-column="100" selection-end-line="117" selection-end-column="100" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="sort_date.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/sort_date.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<caret line="118" lean-forward="true" selection-start-line="118" selection-end-line="118" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
@ -49,6 +66,9 @@
<findStrings>
<find />
<find>cam.read</find>
<find>dates_orig</find>
<find>dates</find>
<find>shelf_new</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -60,6 +80,8 @@
<option value="$PROJECT_DIR$/run.py" />
<option value="$PROJECT_DIR$/zbar_live.py" />
<option value="$PROJECT_DIR$/raspberry_zbar.py" />
<option value="$PROJECT_DIR$/sort_date.py" />
<option value="$PROJECT_DIR$/generate_moves.py" />
<option value="$PROJECT_DIR$/main.py" />
</list>
</option>
@ -139,6 +161,25 @@
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
<configuration name="generate_moves" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="Barcode_Reader_Python" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/generate_moves.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="Barcode_Reader_Python" />
<option name="INTERPRETER_OPTIONS" value="" />
@ -177,14 +218,37 @@
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
<configuration name="sort_date" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="Barcode_Reader_Python" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/sort_date.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
<list>
<item itemvalue="Python.raspberry_live" />
<item itemvalue="Python.RUN" />
<item itemvalue="Python.main" />
<item itemvalue="Python.sort_date" />
<item itemvalue="Python.generate_moves" />
</list>
<recent_temporary>
<list>
<item itemvalue="Python.main" />
<item itemvalue="Python.generate_moves" />
<item itemvalue="Python.sort_date" />
</list>
</recent_temporary>
</component>
@ -202,22 +266,23 @@
<servers />
</component>
<component name="ToolWindowManager">
<frame x="1920" y="-4" width="1366" height="772" extended-state="6" />
<frame x="1920" y="-4" width="1366" height="772" extended-state="7" />
<editor active="true" />
<layout>
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Event Log" order="7" sideWeight="0.5007587" side_tool="true" weight="0.4638365" />
<window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49924126" weight="0.27056962" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Python Console" order="7" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49924126" visible="true" weight="0.27056962" />
<window_info anchor="bottom" id="Terminal" order="7" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.26327768" />
<window_info content_ui="combo" id="Project" order="0" weight="0.26783004" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="right" id="Database" order="3" />
<window_info anchor="right" id="SciView" order="3" weight="0.32928678" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39873418" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39873418" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.24962063" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
@ -226,6 +291,29 @@
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32911393" />
</layout>
<layout-to-restore>
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.24962063" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.26783004" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" id="SciView" order="3" weight="0.32928678" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Database Changes" order="9" show_stripe_button="false" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49924126" visible="true" weight="0.27056962" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32911393" />
<window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39873418" />
<window_info anchor="right" id="Database" order="4" />
<window_info anchor="bottom" id="Terminal" order="11" />
<window_info anchor="bottom" id="Event Log" order="12" sideWeight="0.5007587" side_tool="true" weight="0.4638365" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info id="Favorites" order="2" side_tool="true" />
</layout-to-restore>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
@ -240,25 +328,25 @@
<entry file="file://$PROJECT_DIR$/run.py" />
<entry file="file://$PROJECT_DIR$/barcodes.csv" />
<entry file="file://$PROJECT_DIR$/raspberry_zbar.py" />
<entry file="file://$PROJECT_DIR$/zbar_live.py">
<entry file="file://$PROJECT_DIR$/zbar_live.py" />
<entry file="file://$PROJECT_DIR$/generate_moves.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="400">
<caret line="33" selection-start-line="33" selection-end-line="33" />
<folding>
<element signature="e#0#25#0" expanded="true" />
</folding>
<state relative-caret-position="285">
<caret line="117" column="100" selection-start-line="117" selection-start-column="100" selection-end-line="117" selection-end-column="100" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/generate_moves.py">
<entry file="file://$PROJECT_DIR$/sort_date.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-630" />
<state relative-caret-position="315">
<caret line="118" lean-forward="true" selection-start-line="118" selection-end-line="118" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="375">
<caret line="61" column="9" selection-start-line="61" selection-start-column="9" selection-end-line="61" selection-end-column="9" />
<state relative-caret-position="285">
<caret line="75" lean-forward="true" selection-start-line="75" selection-end-line="75" />
<folding>
<element signature="e#32#69#0" expanded="true" />
</folding>


BIN
Barcode_Reader_Python/database_actions.pyc View File


+ 66
- 54
Barcode_Reader_Python/generate_moves.py View File

@ -1,29 +1,12 @@
import sort_date
exp_date , dates_orig = sort_date.calcDate()
shelf_back = exp_date[:]
try:
expired = exp_date.count(-1)
for i in range(expired):
shelf_back.pop(shelf_back.index(-1))
shelf_new = sorted(shelf_back)
for i in range(expired):
shelf_new.append(-1)
except ValueError:
print('')
exp_date.append(None)
shelf_new.append(None)
repeats = 0
correct_locs = []
temp = None
moved_item = None
moved_item_loc = None
print "\n\n\n//////////////////////////////////////////////////////////////////////////////"
print(" {} ".format(exp_date))
print(" {} ".format(shelf_new))
print "/////////////////////////////////////////////////////////////////////////////\n\n\n"
exp_date = []
shelf_new = []
repeats = 0
def backArray(myArray):
global shelf_back
@ -31,6 +14,7 @@ def backArray(myArray):
for i in range(len(myArray)):
shelf_back.append(myArray[i])
def eqArray(myArray):
global exp_date
exp_date = []
@ -45,62 +29,90 @@ def place():
global shelf_back
repeats += 1
backArray(exp_date)
if (exp_date[len(exp_date)-1] != None):
moved_item = None
moved_item_loc = None
if (exp_date[len(exp_date) - 1] != None):
empty_loc = exp_date.index(None)
moved_item_loc = exp_date.index(shelf_new[empty_loc])
reps=0
reps = 0
while True:
reps += 1
if(moved_item_loc in correct_locs):
if (moved_item_loc in correct_locs):
exp_date.pop(moved_item_loc)
moved_item_loc = exp_date.index(shelf_new[empty_loc]) + reps
continue
break
eqArray(shelf_back)
moved_item = exp_date[moved_item_loc]
if(exp_date[moved_item_loc] != shelf_new[moved_item_loc]):
if (exp_date[moved_item_loc] != shelf_new[moved_item_loc]):
exp_date[moved_item_loc] = None
exp_date[empty_loc] = moved_item
correct_locs.append(empty_loc)
print " Moved item {0} to location {1}. Location {2} is now empty!".format(moved_item,empty_loc + 1, moved_item_loc + 1)
print " Moved item {0} to location {1}. Location {2} is now empty!".format(moved_item, empty_loc + 1,
moved_item_loc + 1)
print "============================================================================"
else:
print " Leaving item {0} in location {1}. Location {2} is still empty!".format(moved_item, moved_item_loc + 1,empty_loc + 1)
print " Leaving item {0} in location {1}. Location {2} is still empty!".format(moved_item,
moved_item_loc + 1,
empty_loc + 1)
print "============================================================================"
correct_locs.append(moved_item_loc)
place()
else:
return
def generate(dates,date_cur):
global exp_date
global shelf_new
global repeats
exp_date = sort_date. calcDate(dates,date_cur)
shelf_back = exp_date[:]
try:
expired = exp_date.count(-1)
for i in range(expired):
shelf_back.pop(shelf_back.index(-1))
shelf_new = sorted(shelf_back)
for i in range(expired):
shelf_new.append(-1)
except ValueError:
print('')
exp_date.append(None)
shelf_new.append(None)
repeats = 0
while True:
if(repeats < len(exp_date)):
for i in range(len(exp_date)):
if(exp_date[len(exp_date)-1] == None):
if(exp_date[i] == shelf_new[i]):
continue
else:
exp_date[len(exp_date)-1] = exp_date[i]
print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print ' TEMP IS EMPTY, MOVING {0} FROM LOCATION {1} TO THE TEMP'.format(exp_date[i],i+1)
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
print "============================================================================"
exp_date[i] = None
print "\n\n\n//////////////////////////////////////////////////////////////////////////////"
print(" {} ".format(exp_date))
print(" {} ".format(shelf_new))
print "/////////////////////////////////////////////////////////////////////////////\n\n\n"
while True:
if(repeats < len(exp_date)):
for i in range(len(exp_date)):
if(exp_date[len(exp_date)-1] == None):
if(exp_date[i] == shelf_new[i]):
continue
else:
exp_date[len(exp_date)-1] = exp_date[i]
print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print ' TEMP IS EMPTY, MOVING {0} FROM LOCATION {1} TO THE TEMP'.format(exp_date[i],i+1)
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
print "============================================================================"
exp_date[i] = None
else:
break
place()
try:
print('***********************************************************************************')
print(' The last {} items have expired, throwing them away.'.format(len(exp_date)-shelf_new.index(-1)-1))
print('***********************************************************************************')
except ValueError:
print(" No items have expired")
print('***********************************************************************************')
else:
break
place()
try:
print('***********************************************************************************')
print(' The last {} items have expired, throwing them away.'.format(len(exp_date)-shelf_new.index(-1)-1))
print('***********************************************************************************')
except ValueError:
print(" No items have expired")
print('***********************************************************************************')

BIN
Barcode_Reader_Python/generate_moves.pyc View File


+ 18
- 2
Barcode_Reader_Python/main.py View File

@ -5,10 +5,23 @@ import imutils
import time
import cv2
import database_actions
import datetime
import generate_moves
# initialize the video stream and allow the camera sensor to warm up
print("[INFO] starting video stream...")
def dateStr():
date_cur = ""
if len(str(datetime.date.today().day)) == 1:
date_cur = date_cur + "0" + str(datetime.date.today().day) + "."
else:
date_cur = date_cur + str(datetime.date.today().day) + "."
if len(str(datetime.date.today().month)) == 1:
date_cur = date_cur + "0" + str(datetime.date.today().month) + "."
else:
date_cur = date_cur + str(datetime.date.today().month) + "."
date_cur += str(datetime.date.today().year)
return date_cur
# vs = VideoStream(src=0).start()
vs = VideoStream().start()
time.sleep(2.0)
@ -17,8 +30,9 @@ reps = 0
barcodes = None
prevcode = None
exp_date = []
current_date = dateStr()
print current_date
# loop over the frames from the video stream
while reps<1:
# grab the frame from the threaded video stream and resize it to
@ -58,5 +72,7 @@ while reps<1:
# close the output CSV file do a bit of cleanup
print("[INFO] cleaning up...")
print dates
generate_moves.generate(dates,current_date)
cv2.destroyAllWindows()
vs.stop()

+ 118
- 117
Barcode_Reader_Python/sort_date.py View File

@ -1,117 +1,118 @@
def dateComp(date_one,date_two):
date_one_id = date_one.split('.')
date_two_id = date_two.split('.')
if(int(date_one_id[2]) > int(date_two_id[2])):
return True
elif(int(date_one_id[2]) == int(date_two_id[2])):
if(int(date_one_id[1]) > int(date_two_id[1])):
return True
elif(int(date_one_id[1]) == int(date_two_id[1])):
if(int(date_one_id[0]) > int(date_two_id[0])):
return True
elif(int(date_one_id[0]) == int(date_two_id[0])):
return True
return False
def addItem(list_bas,item,item_loc):
new_list = list_bas[0:item_loc]
new_list.append(item)
for i in range(len(list_bas) - item_loc):
new_list.append(list_bas[item_loc + i])
return new_list
def expDate(current_date,prod_dates):
thrown_away = []
thrown_locs = []
thrown_number = 0
for i in range(len(prod_dates)):
if(dateComp(current_date,prod_dates[i])):
thrown_away.append(prod_dates[i])
thrown_locs.append(i)
for i in range(len(thrown_locs)):
prod_dates.pop(thrown_locs[i]-thrown_number)
thrown_number += 1
def dateSort(current_date,prod_dates):
loc = None
sorted_dates = []
prev_placed = True
for i in range(len(prod_dates)):
if(dateComp(prod_dates[i],current_date)):
sorted_dates.append(prod_dates[i])
loc = i
break
for i in range(len(prod_dates)):
if(loc == i):
continue
prev_placed = True
for j in range(len(sorted_dates)):
if(prev_placed):
if(j==0):
if(dateComp(sorted_dates[j],prod_dates[i])):
sorted_dates = addItem(sorted_dates,prod_dates[i],0)
prev_placed = False
continue
if(j == len(sorted_dates) - 1 ):
if(dateComp(prod_dates[i],sorted_dates[j])):
sorted_dates = addItem(sorted_dates,prod_dates[i],len(sorted_dates))
else:
sorted_dates = addItem(sorted_dates,prod_dates[i],len(sorted_dates)-1)
continue
if(dateComp(prod_dates[i],sorted_dates[j])):
if(dateComp(sorted_dates[j+1],prod_dates[i])):
sorted_dates = addItem(sorted_dates,prod_dates[i],j+1)
prev_placed = False
continue
if(dateComp(sorted_dates[j],prod_dates[i])):
if(dateComp(prod_dates[i],sorted_dates[j-1])):
sorted_dates = addItem(sorted_dates,prod_dates[i],i)
prev_placed = False
continue
return sorted_dates
def dateToint(sorted_dates,unsorted_dates,date_current):
date_num = 0
prev_date = None
sorted_dateInt = []
unsorted_dateInt = []
for i in range(len(sorted_dates)):
if(dateComp(date_current,sorted_dates[i])):
sorted_dateInt.append(-1)
continue
if(prev_date == sorted_dates[i]):
sorted_dateInt.append(date_num)
continue
date_num += 1
sorted_dateInt.append(date_num)
prev_date = sorted_dates[i]
for i in unsorted_dates:
unsorted_dateInt.append(sorted_dateInt[sorted_dates.index(i)])
return unsorted_dateInt
def listDif(list1,list2):
listOrig = list1
for i in list2:
if(i in listOrig):
listOrig.pop(listOrig.index(i))
return listOrig
def calcDate():
date_cur = '23.06.2018'
exp_dates = ['23.06.2019','22.06.2019','11.06.2018','24.06.2018','23.08.2018','23.04.2018']
exp_dates_process = exp_dates[:]
sorted_date = dateSort(date_cur,exp_dates_process)
date_int = dateToint(sorted_date,exp_dates,date_cur)
return date_int,sorted_date
def dateComp(date_one, date_two):
date_one_id = date_one.split('.')
date_two_id = date_two.split('.')
if int(date_one_id[2]) > int(date_two_id[2]):
return True
elif int(date_one_id[2]) == int(date_two_id[2]):
if int(date_one_id[1]) > int(date_two_id[1]):
return True
elif int(date_one_id[1]) == int(date_two_id[1]):
if int(date_one_id[0]) > int(date_two_id[0]):
return True
elif int(date_one_id[0]) == int(date_two_id[0]):
return True
return False
def addItem(list_bas, item, item_loc):
new_list = list_bas[0:item_loc]
new_list.append(item)
for i in range(len(list_bas) - item_loc):
new_list.append(list_bas[item_loc + i])
return new_list
def expDate(current_date, prod_dates):
thrown_away = []
thrown_locs = []
thrown_number = 0
for i in range(len(prod_dates)):
if dateComp(current_date, prod_dates[i]):
thrown_away.append(prod_dates[i])
thrown_locs.append(i)
for i in range(len(thrown_locs)):
prod_dates.pop(thrown_locs[i] - thrown_number)
thrown_number += 1
def dateSort(current_date, prod_dates):
loc = None
sorted_dates = []
prev_placed = True
for i in range(len(prod_dates)):
if dateComp(prod_dates[i], current_date):
sorted_dates.append(prod_dates[i])
loc = i
break
for i in range(len(prod_dates)):
if (loc == i):
continue
prev_placed = True
for j in range(len(sorted_dates)):
if prev_placed:
if j == 0:
if dateComp(sorted_dates[j], prod_dates[i]):
sorted_dates = addItem(sorted_dates, prod_dates[i], 0)
prev_placed = False
continue
if j == len(sorted_dates) - 1:
if dateComp(prod_dates[i], sorted_dates[j]):
sorted_dates = addItem(sorted_dates, prod_dates[i], len(sorted_dates))
else:
sorted_dates = addItem(sorted_dates, prod_dates[i], len(sorted_dates) - 1)
continue
if dateComp(prod_dates[i], sorted_dates[j]):
if dateComp(sorted_dates[j + 1], prod_dates[i]):
sorted_dates = addItem(sorted_dates, prod_dates[i], j + 1)
prev_placed = False
continue
if dateComp(sorted_dates[j], prod_dates[i]):
if dateComp(prod_dates[i], sorted_dates[j - 1]):
sorted_dates = addItem(sorted_dates, prod_dates[i], i)
prev_placed = False
continue
return sorted_dates
def dateToint(sorted_dates, unsorted_dates, date_current):
date_num = 0
prev_date = None
sorted_dateInt = []
unsorted_dateInt = []
for i in range(len(sorted_dates)):
if (dateComp(date_current, sorted_dates[i])):
sorted_dateInt.append(-1)
continue
if (prev_date == sorted_dates[i]):
sorted_dateInt.append(date_num)
continue
date_num += 1
sorted_dateInt.append(date_num)
prev_date = sorted_dates[i]
for i in unsorted_dates:
unsorted_dateInt.append(sorted_dateInt[sorted_dates.index(i)])
return unsorted_dateInt
def listDif(list1, list2):
listOrig = list1
for i in list2:
if i in listOrig:
listOrig.pop(listOrig.index(i))
return listOrig
def calcDate(exp_dates, date_cur):
exp_dates_process = exp_dates[:]
sorted_date = dateSort(date_cur, exp_dates_process)
date_int = dateToint(sorted_date, exp_dates, date_cur)
return date_int

BIN
Barcode_Reader_Python/sort_date.pyc View File


Loading…
Cancel
Save