Skip to content

Commit

Permalink
Redo AC example
Browse files Browse the repository at this point in the history
Old example uses dataset that doesn't contain dates in proper format
but the main functionality is similar, so I decided to change the
dataset
  • Loading branch information
egshnov committed Dec 21, 2023
1 parent 104f592 commit 0eacfc8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions examples/algebraic_constraints.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import desbordante
import pandas
import operator
from datetime import datetime

TABLE = 'examples/datasets/cargo_march.csv'
# Note that dates in the given dataset must be in the format Y-M-D
TABLE = 'examples/datasets/ACShippingDates.csv'
HEADER = 0
SEPARATOR = ','
P_FUZZ = 0.85
FUZZINESS = 0.2
P_FUZZ = 0.7
FUZZINESS = 0.3
BUMPS_LIMIT = 0
WEIGHT = 0.1
BIN_OPERATION = '-'
AC_SEED = 11
ITERATIONS_LIMIT = 4
ITERATIONS_LIMIT = 10
OPERATIONS = {
'+': (operator.add, 'Sum'),
'-': (operator.sub, 'Difference'),
Expand All @@ -23,7 +25,7 @@
algo = desbordante.ACAlgorithm()

df = pandas.read_csv(TABLE, sep=SEPARATOR, header=HEADER)
df_without_id = df[['Delivery date', 'Dispatch date']]
df_without_id = df[['deliveryDate', 'shipDate']]

algo.load_data(df=df_without_id)

Expand All @@ -33,18 +35,20 @@
ac_ranges = algo.get_ac_ranges()
for ac_range in ac_ranges:
l_col = df_without_id.columns[ac_range.column_indices[0]]
r_col = df_without_id.columns[ac_range.column_indices[1]]
r_col = df_without_id.columns[ac_range.column_indices[1]]
print(f'Discovered ranges for ({l_col} {BIN_OPERATION} {r_col}) are:')
print(ac_range.ranges)

ac_exceptions = algo.get_ac_exceptions()
print()
print(f'Rows in which the result of the chosen operation ({BIN_OPERATION}) is outside of discovered ranges:')
for ac_exception in ac_exceptions:
id, delivery_date, dispatch_date = df.iloc[ac_exception.row_index]
id, delievery_date, ship_date = df.iloc[ac_exception.row_index]
print(f'id: {id}')
print(f'Dispatch date: {dispatch_date}')
print(f'Delivery date: {delivery_date}')
print(f'{operation_name}: {operation(delivery_date, dispatch_date)}')
print(f'Shipping date : {ship_date}')
print(f'Delivery date: {delievery_date}')
date1 = datetime.strptime(ship_date, '%Y-%m-%d').date()
date2 = datetime.strptime(delievery_date, '%Y-%m-%d').date()
print(f'{operation_name}: {operation(date2, date1).days}')
print()

0 comments on commit 0eacfc8

Please sign in to comment.