You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.8 KiB

  1. def dateComp(date_one, date_two):
  2. date_one_id = date_one.split('.')
  3. date_two_id = date_two.split('.')
  4. if int(date_one_id[2]) > int(date_two_id[2]):
  5. return True
  6. elif int(date_one_id[2]) == int(date_two_id[2]):
  7. if int(date_one_id[1]) > int(date_two_id[1]):
  8. return True
  9. elif int(date_one_id[1]) == int(date_two_id[1]):
  10. if int(date_one_id[0]) > int(date_two_id[0]):
  11. return True
  12. elif int(date_one_id[0]) == int(date_two_id[0]):
  13. return True
  14. return False
  15. def addItem(list_bas, item, item_loc):
  16. new_list = list_bas[0:item_loc]
  17. new_list.append(item)
  18. for i in range(len(list_bas) - item_loc):
  19. new_list.append(list_bas[item_loc + i])
  20. return new_list
  21. def expDate(current_date, prod_dates):
  22. thrown_away = []
  23. thrown_locs = []
  24. thrown_number = 0
  25. for i in range(len(prod_dates)):
  26. if dateComp(current_date, prod_dates[i]):
  27. thrown_away.append(prod_dates[i])
  28. thrown_locs.append(i)
  29. for i in range(len(thrown_locs)):
  30. prod_dates.pop(thrown_locs[i] - thrown_number)
  31. thrown_number += 1
  32. def dateSort(current_date, prod_dates):
  33. loc = None
  34. sorted_dates = []
  35. prev_placed = True
  36. for i in range(len(prod_dates)):
  37. if dateComp(prod_dates[i], current_date):
  38. sorted_dates.append(prod_dates[i])
  39. loc = i
  40. break
  41. for i in range(len(prod_dates)):
  42. if (loc == i):
  43. continue
  44. prev_placed = True
  45. for j in range(len(sorted_dates)):
  46. if prev_placed:
  47. if j == 0:
  48. if dateComp(sorted_dates[j], prod_dates[i]):
  49. sorted_dates = addItem(sorted_dates, prod_dates[i], 0)
  50. prev_placed = False
  51. continue
  52. if j == len(sorted_dates) - 1:
  53. if dateComp(prod_dates[i], sorted_dates[j]):
  54. sorted_dates = addItem(sorted_dates, prod_dates[i], len(sorted_dates))
  55. else:
  56. sorted_dates = addItem(sorted_dates, prod_dates[i], len(sorted_dates) - 1)
  57. continue
  58. if dateComp(prod_dates[i], sorted_dates[j]):
  59. if dateComp(sorted_dates[j + 1], prod_dates[i]):
  60. sorted_dates = addItem(sorted_dates, prod_dates[i], j + 1)
  61. prev_placed = False
  62. continue
  63. if dateComp(sorted_dates[j], prod_dates[i]):
  64. if dateComp(prod_dates[i], sorted_dates[j - 1]):
  65. sorted_dates = addItem(sorted_dates, prod_dates[i], i)
  66. prev_placed = False
  67. continue
  68. return sorted_dates
  69. def dateToint(sorted_dates, unsorted_dates, date_current):
  70. date_num = 0
  71. prev_date = None
  72. sorted_dateInt = []
  73. unsorted_dateInt = []
  74. for i in range(len(sorted_dates)):
  75. if (dateComp(date_current, sorted_dates[i])):
  76. sorted_dateInt.append(-1)
  77. continue
  78. if (prev_date == sorted_dates[i]):
  79. sorted_dateInt.append(date_num)
  80. continue
  81. date_num += 1
  82. sorted_dateInt.append(date_num)
  83. prev_date = sorted_dates[i]
  84. for i in unsorted_dates:
  85. unsorted_dateInt.append(sorted_dateInt[sorted_dates.index(i)])
  86. return unsorted_dateInt
  87. def listDif(list1, list2):
  88. listOrig = list1
  89. for i in list2:
  90. if i in listOrig:
  91. listOrig.pop(listOrig.index(i))
  92. return listOrig
  93. def calcDate(exp_dates, date_cur):
  94. exp_dates_process = exp_dates[:]
  95. sorted_date = dateSort(date_cur, exp_dates_process)
  96. date_int = dateToint(sorted_date, exp_dates, date_cur)
  97. return date_int