concurrentusage:index
Differences
This shows you the differences between two versions of the page.
| concurrentusage:index [2024/10/08 10:18] – created antonio.andriychuk | concurrentusage:index [2026/04/09 10:17] (current) – removed sysadm | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Concurrent Usage Script ====== | ||
| - | |||
| - | <code python> | ||
| - | import pandas as pd | ||
| - | import datetime | ||
| - | import json | ||
| - | |||
| - | # Creating the Dates used to rename the files at the end of the process | ||
| - | today = datetime.date.today() | ||
| - | first = today.replace(day=1) | ||
| - | last_month = first - datetime.timedelta(days=1) | ||
| - | |||
| - | year = last_month.strftime(" | ||
| - | month = last_month.strftime(" | ||
| - | |||
| - | # Dictionary to map month numbers to month names | ||
| - | months_dict = { | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | } | ||
| - | |||
| - | # Update month name using the dictionary | ||
| - | month_name = months_dict.get(month) | ||
| - | |||
| - | # Retrieving DataFrame | ||
| - | df = pd.read_csv(' | ||
| - | |||
| - | # Dropping last 5 rows | ||
| - | df.drop(df.tail(5).index, | ||
| - | |||
| - | # Convert " | ||
| - | df[' | ||
| - | |||
| - | # Filter DataFrame based on year and month | ||
| - | filtered_df = df[(df[' | ||
| - | |||
| - | # Initialize an empty list to store the formatted rows | ||
| - | formatted_rows = [] | ||
| - | |||
| - | # filtered_df.to_csv(" | ||
| - | |||
| - | # Iterate over each row in the filtered DataFrame | ||
| - | for index, row in filtered_df.iterrows(): | ||
| - | # Extract the values from the columns | ||
| - | time = row[' | ||
| - | user = row[' | ||
| - | tenant = row[' | ||
| - | |||
| - | # Format the row as a JSON object with a comma at the end | ||
| - | formatted_row = ' | ||
| - | formatted_rows.append(formatted_row) | ||
| - | |||
| - | # Remove the comma and newline from the last row | ||
| - | if formatted_rows: | ||
| - | formatted_rows[-1] = formatted_rows[-1][: | ||
| - | |||
| - | # Construct the JSON array | ||
| - | json_data = ' | ||
| - | |||
| - | # Request user whether it's FK or SYD | ||
| - | region = input(' | ||
| - | |||
| - | list_region = [' | ||
| - | |||
| - | if region not in list_region: | ||
| - | print(' | ||
| - | exit() | ||
| - | else: | ||
| - | match region: | ||
| - | case ' | ||
| - | region = ' | ||
| - | case ' | ||
| - | region = ' | ||
| - | case ' | ||
| - | region = ' | ||
| - | case ' | ||
| - | region = ' | ||
| - | |||
| - | # Save the .csv file | ||
| - | filtered_df.to_csv(' | ||
| - | |||
| - | # Write the JSON data to a file | ||
| - | with open(' | ||
| - | json_file.write(json_data) | ||
| - | |||
| - | # Re-loads the file | ||
| - | array = json.loads(json_data) | ||
| - | |||
| - | # Setting variables | ||
| - | t = '' | ||
| - | sum = 0 | ||
| - | max = [] | ||
| - | |||
| - | # Saves a list of UNIQUE tenant names | ||
| - | ten = [{" | ||
| - | b = False | ||
| - | |||
| - | for i in range(len(array)): | ||
| - | for j in range(len(ten)): | ||
| - | if ten[j][" | ||
| - | b = True | ||
| - | if not b: | ||
| - | tmp = {" | ||
| - | ten.append(tmp) | ||
| - | b = False | ||
| - | |||
| - | |||
| - | # Sums of the concurrent tenants per each timeframe, used for the next step to find the maximum licence usage | ||
| - | for i in range(len(array)): | ||
| - | if t == array[i][" | ||
| - | for j in range(len(ten)): | ||
| - | if ten[j][" | ||
| - | if not ten[j][" | ||
| - | sum += array[i][" | ||
| - | ten[j][" | ||
| - | else: | ||
| - | t = array[i][" | ||
| - | temp = {" | ||
| - | max.append(temp) | ||
| - | for j in range(len(ten)): | ||
| - | ten[j][" | ||
| - | for j in range(len(ten)): | ||
| - | if ten[j][" | ||
| - | if not ten[j][" | ||
| - | sum = array[i][" | ||
| - | ten[j][" | ||
| - | |||
| - | |||
| - | # This line will just find the maximum licence usage | ||
| - | res = None | ||
| - | tmp = 0 | ||
| - | for i in range(len(max)): | ||
| - | if tmp < max[i][" | ||
| - | res = max[i] | ||
| - | tmp = max[i][" | ||
| - | |||
| - | # Prints the maximum of connected licence on the platform | ||
| - | print(" | ||
| - | |||
| - | |||
| - | filtered_df.to_csv(" | ||
| - | </ | ||
concurrentusage/index.1728382738.txt.gz · Last modified: by antonio.andriychuk
