Krishna Kumar S commited on
Commit
fd90912
·
1 Parent(s): fad5d14

Revert "commit"

Browse files

This reverts commit fad5d146a6397069e433713378f4b21b0a18e776.

Files changed (2) hide show
  1. Generate_Data.py +152 -43
  2. Read_Data.py +6 -8
Generate_Data.py CHANGED
@@ -1,54 +1,163 @@
1
  import pandas as pd
 
 
 
2
 
3
- def load_excel_data(filepath):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  """
5
- Reads an Excel file and loads specific sheets into dataframes.
6
- Extracts a weightage dictionary from the 'Weightage' sheet.
7
 
8
  Parameters:
9
- filepath (str): Path to the Excel file.
10
-
11
- Returns:
12
- tuple: A dictionary containing weightages and individual dataframes.
 
 
 
 
 
 
 
 
 
 
13
  """
14
- # Define the sheet names to be read
15
- sheets = [
16
- 'Weightage', 'Priority Data', 'Warehouse Data', 'Order Data',
17
- 'Cost Data', 'Distance Data', 'Days Data'
18
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- # Read the 'Weightage' sheet and create a dictionary
21
- weightage_df = pd.read_excel(filepath, sheet_name='Weightage')
22
- weightage_dict = dict(zip(weightage_df['Variable'], weightage_df['Weightage']))
 
 
 
 
 
 
 
 
23
 
24
- # Read all other sheets into separate dataframes
25
- priority_df = pd.read_excel(filepath, sheet_name='Priority Data')
26
- warehouse_df = pd.read_excel(filepath, sheet_name='Warehouse Data')
27
- order_df = pd.read_excel(filepath, sheet_name='Order Data')
28
- cost_df = pd.read_excel(filepath, sheet_name='Cost Data')
29
- distance_df = pd.read_excel(filepath, sheet_name='Distance Data')
30
- days_df = pd.read_excel(filepath, sheet_name='Days Data')
31
 
32
- return weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df
 
 
 
 
33
 
34
  if __name__ == "__main__":
35
- filepath = 'Intelligent_Sourcing.xlsx' # Example file path
36
- weightage_dict, priority_df, warehouse_df, order_df, cost_df, distance_df, days_df = load_excel_data(filepath)
37
-
38
- # Print output for verification
39
- print("Weightage Dictionary:")
40
- print(weightage_dict)
41
-
42
- print("\nLoaded DataFrames:")
43
- print(f"\nPriority Data: {priority_df.shape} rows and columns")
44
- print(priority_df.head())
45
- print(f"\nWarehouse Data: {warehouse_df.shape} rows and columns")
46
- print(warehouse_df.head())
47
- print(f"\nOrder Data: {order_df.shape} rows and columns")
48
- print(order_df.head())
49
- print(f"\nCost Data: {cost_df.shape} rows and columns")
50
- print(cost_df.head())
51
- print(f"\nDistance Data: {distance_df.shape} rows and columns")
52
- print(distance_df.head())
53
- print(f"\nDays Data: {days_df.shape} rows and columns")
54
- print(days_df.head())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
+ import numpy as np
3
+ from io import StringIO
4
+ import matplotlib.pyplot as plt
5
 
6
+ def generate_intelligent_sourcing_excel(
7
+ output_filename,
8
+ num_of_warehouses,
9
+ num_of_products,
10
+ num_of_orders,
11
+ weightage_Cost,
12
+ weightage_Priority,
13
+ weightage_distance,
14
+ weightage_days,
15
+ range_priority,
16
+ range_prod_stock,
17
+ range_order,
18
+ range_cost,
19
+ range_distance,
20
+ range_days
21
+ ):
22
  """
23
+ Generates an Excel file containing warehouse, order, and shipping data.
 
24
 
25
  Parameters:
26
+ output_filename (str): The name of the output Excel file.
27
+ num_of_warehouses (int): Number of warehouses.
28
+ num_of_products (int): Number of products.
29
+ num_of_orders (int): Number of orders.
30
+ weightage_Cost (float): Weightage for cost.
31
+ weightage_Priority (float): Weightage for priority.
32
+ weightage_distance (float): Weightage for distance.
33
+ weightage_days (float): Weightage for days.
34
+ range_priority (tuple): Range for priority values.
35
+ range_prod_stock (tuple): Range for product stock values.
36
+ range_order (tuple): Range for order quantities.
37
+ range_cost (tuple): Range for cost values.
38
+ range_distance (tuple): Range for distance values.
39
+ range_days (tuple): Range for delivery days values.
40
  """
41
+ rng = np.random.default_rng(seed=42) # Random number generator
42
+
43
+ # Create weightage DataFrame
44
+ weightage_df = pd.DataFrame({
45
+ 'Variable': ['Cost', 'Priority', 'Distance', 'Days'],
46
+ 'Weightage': [weightage_Cost, weightage_Priority, weightage_distance, weightage_days]
47
+ })
48
+
49
+ # Generate priority data
50
+ priority_df = pd.DataFrame({
51
+ 'Warehouse': [f'Warehouse#{w}' for w in range(1, num_of_warehouses + 1)],
52
+ 'Priority': rng.integers(*range_priority, size=num_of_warehouses)
53
+ })
54
+
55
+ # Generate warehouse stock data
56
+ warehouse_df = pd.DataFrame({
57
+ 'Warehouse': [f'Warehouse#{w}' for w in range(1, num_of_warehouses + 1)]
58
+ })
59
+ for p in range(1, num_of_products + 1):
60
+ warehouse_df[f'Product#{p}'] = rng.integers(*range_prod_stock, size=num_of_warehouses)
61
+
62
+ # Generate order data
63
+ order_df = pd.DataFrame({
64
+ 'Order': [f'Order#{o}' for o in range(1, num_of_orders + 1)]
65
+ })
66
+ for p in range(1, num_of_products + 1):
67
+ order_df[f'Product#{p}'] = rng.integers(*range_order, size=num_of_orders)
68
+
69
+ # Function to generate shipping data
70
+ def generate_shipping_data(metric_name, value_range):
71
+ return pd.DataFrame([
72
+ (w, o, p, rng.integers(*value_range))
73
+ for w in warehouse_df["Warehouse"]
74
+ for o in order_df["Order"]
75
+ for p in warehouse_df.columns[1:]
76
+ ], columns=["Warehouse", "Order", "Product", metric_name])
77
+
78
+ # Generate cost, distance, and days DataFrames
79
+ cost_df = generate_shipping_data("Cost", range_cost)
80
+ distance_df = generate_shipping_data("Distance", range_distance)
81
+ days_df = generate_shipping_data("Days", range_days)
82
+
83
+ # Write data to Excel
84
+ with pd.ExcelWriter(output_filename, engine='xlsxwriter') as writer:
85
+ weightage_df.to_excel(writer, sheet_name='Weightage', index=False)
86
+ priority_df.to_excel(writer, sheet_name='Priority Data', index=False)
87
+ warehouse_df.to_excel(writer, sheet_name='Warehouse Data', index=False)
88
+ order_df.to_excel(writer, sheet_name='Order Data', index=False)
89
+ cost_df.to_excel(writer, sheet_name='Cost Data', index=False)
90
+ distance_df.to_excel(writer, sheet_name='Distance Data', index=False)
91
+ days_df.to_excel(writer, sheet_name='Days Data', index=False)
92
+
93
+ print(f"Excel file '{output_filename}' has been successfully created.")
94
+ return
95
+
96
+
97
+ def plot_histograms(excel_filename):
98
+ """
99
+ Reads the generated Excel file and plots separate histograms for relevant data columns.
100
+ """
101
+ xls = pd.ExcelFile(excel_filename)
102
 
103
+ data_sheets = {
104
+ "Priority": pd.read_excel(xls, "Priority Data")["Priority"],
105
+ "Product Stock": pd.read_excel(xls, "Warehouse Data").iloc[:, 1:].values.flatten(),
106
+ "Order Quantity": pd.read_excel(xls, "Order Data").iloc[:, 1:].values.flatten(),
107
+ "Cost": pd.read_excel(xls, "Cost Data")["Cost"],
108
+ "Distance": pd.read_excel(xls, "Distance Data")["Distance"],
109
+ "Days": pd.read_excel(xls, "Days Data")["Days"]
110
+ }
111
+
112
+ fig, axes = plt.subplots(2, 3, figsize=(15, 10))
113
+ axes = axes.flatten()
114
 
115
+ for i, (label, data) in enumerate(data_sheets.items()):
116
+ axes[i].hist(data, bins=20, alpha=0.7, color='blue', edgecolor='black')
117
+ axes[i].set_title(label)
118
+ axes[i].set_xlabel("Value")
119
+ axes[i].set_ylabel("Frequency")
120
+ axes[i].grid(True)
 
121
 
122
+ plt.tight_layout()
123
+ plt.savefig("histogram_ranges.png")
124
+ plt.close()
125
+ print("Histogram saved as 'histogram_ranges.png'")
126
+
127
 
128
  if __name__ == "__main__":
129
+ # Define parameters for execution
130
+ output_filename = "Intelligent_Sourcing.xlsx"
131
+ num_of_warehouses = 4
132
+ num_of_products = 10
133
+ num_of_orders = 2
134
+ weightage_Cost = 1
135
+ weightage_Priority = 0.8
136
+ weightage_distance = 0.6
137
+ weightage_days = 0.4
138
+ range_priority = (1, 10)
139
+ range_prod_stock = (1, 100)
140
+ range_order = (1, 10)
141
+ range_cost = (1, 300)
142
+ range_distance = (1, 200)
143
+ range_days = (1, 7)
144
+
145
+ # Run function
146
+ generate_intelligent_sourcing_excel(
147
+ output_filename,
148
+ num_of_warehouses,
149
+ num_of_products,
150
+ num_of_orders,
151
+ weightage_Cost,
152
+ weightage_Priority,
153
+ weightage_distance,
154
+ weightage_days,
155
+ range_priority,
156
+ range_prod_stock,
157
+ range_order,
158
+ range_cost,
159
+ range_distance,
160
+ range_days
161
+ )
162
+
163
+ plot_histograms(excel_filename=output_filename)
Read_Data.py CHANGED
@@ -10,14 +10,12 @@ sheets = ['Weightage', 'Priority Data', 'Warehouse Data', 'Order Data', 'Cost Da
10
 
11
  weightage_df = pd.read_excel(filepath, sheet_name='Weightage')
12
  weightage_dict = dict(zip(weightage_df['Variable'], weightage_df['Weightage']))
13
- #Weightage_Cost = weightage_dict["Cost"]
14
- #Weightage_Priority = weightage_dict["Priority"]
15
- #Weightage_distance = weightage_dict["Distance"]
16
- #Weightage_days = weightage_dict["Days"]
17
 
18
  priority_df = pd.read_excel(filepath, sheet_name='Priority Data')
19
  warehouse_df = pd.read_excel(filepath, sheet_name='Warehouse Data')
20
- order_df = pd.read_excel(filepath, sheet_name='Order Data')
21
- cost_df = pd.read_excel(filepath, sheet_name='Cost Data')
22
- Distance_df = pd.read_excel(filepath, sheet_name='Distance Data')
23
- Days_df = pd.read_excel(filepath, sheet_name='Days Data')
 
10
 
11
  weightage_df = pd.read_excel(filepath, sheet_name='Weightage')
12
  weightage_dict = dict(zip(weightage_df['Variable'], weightage_df['Weightage']))
13
+ Weightage_Cost = weightage_dict["Cost"]
14
+ Weightage_Priority = weightage_dict["Priority"]
15
+ Weightage_distance = weightage_dict["Distance"]
16
+ Weightage_days = weightage_dict["Days"]
17
 
18
  priority_df = pd.read_excel(filepath, sheet_name='Priority Data')
19
  warehouse_df = pd.read_excel(filepath, sheet_name='Warehouse Data')
20
+
21
+ print(warehouse_df)