Skip to content
Snippets Groups Projects
Commit 6dc602f9 authored by Max Väistö's avatar Max Väistö
Browse files

Added market performance function to branch

parent fa2404fe
No related branches found
No related tags found
No related merge requests found
...@@ -2,69 +2,7 @@ from typing import Sequence, Optional, Any ...@@ -2,69 +2,7 @@ from typing import Sequence, Optional, Any
import pandas as pd import pandas as pd
import plotly.express as px import plotly.express as px
from dash_plot_generation.utils import get_owner_means, convert_owners_to_limits, split_companies
# Three functions by Max, to get the mean value of game owner and split the company names.
DEFAULT_ILLEGAL_CONTINUATIONS = {"INC.", "LLC", "CO.", "LTD.", "S.R.O."}
def get_owner_means(owner_limits: Sequence[Any]):
if not isinstance(owner_limits, list):
return owner_limits
else:
return (owner_limits[0] + owner_limits[1]) / 2
def convert_owners_to_limits(owner_limit):
if not isinstance(owner_limit, str):
return owner_limit
owners_raw = [rev.replace(" ", "") for rev in owner_limit.split(" .. ")]
owners_clean = []
for owner_limit in owners_raw:
owner_limit = owner_limit.replace("M", "0" * 6)
owner_limit = owner_limit.replace("k", "0" * 3)
owners_clean.append(int(owner_limit))
return owners_clean
def split_companies(arr, illegal_continuations: Optional[Sequence[str]] = None):
"""
Splits the given string at comma sign as long as following the comma none of the illegal
continuations happen. In such a case, the string split does not happen that said comma.
:param arr: Array containing the developers/publishers for a single game
:param illegal_continuations: A list of illegal continuations. Must be uppercase.
:return: Returns the given split input string as a list.
:note: If the arr is numpy.NaN, this value is returned instead of a list.
"""
if illegal_continuations is None:
illegal_continuations = DEFAULT_ILLEGAL_CONTINUATIONS
if pd.isna(arr):
return arr
results_list = []
start_index = 0
split_char = ", "
for index in range(len(arr)):
if index < len(arr) - 1:
txt = arr[index:index + 2]
if txt == split_char:
found_illegal = False
min_continuation = min([len(continuation) for continuation in illegal_continuations])
max_continuation = max([len(continuation) for continuation in illegal_continuations])
next_chars = arr[index + min_continuation:index + min_continuation + max_continuation]
for i in range(index + min_continuation, index + len(next_chars) + 2):
comp_txt = arr[index + 2:i + 2].upper()
if comp_txt in illegal_continuations:
found_illegal = True
break
if not found_illegal:
results_list.append(arr[start_index:index].strip())
start_index = index + 1
elif index == len(arr) - 1:
results_list.append(arr[start_index:index + 1].strip())
return results_list
# The function to plot the bubble chart of market performance # The function to plot the bubble chart of market performance
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment