tpaviot / ProcessScheduler

A Python package for automatic and optimized resource scheduling
https://processscheduler.github.io/
GNU General Public License v3.0
59 stars 18 forks source link

Add number of random colors based on df size #42

Closed magic7s closed 3 years ago

magic7s commented 3 years ago

I ran into an issue where I ran out of colors when rendering the plotly gantt.

magic7s commented 3 years ago

Looks like its working. The Static Code Analysis is failing because I don't use variable i. I goggled a workaround and nothing is clean in python. Let me know what you think.

tpaviot commented 3 years ago

The loop should be simplified as:

for _ in range(len(df)): 
tpaviot commented 3 years ago

ok, tested. I merge your contribution, I will fix it as soon as the commit appears in the master branch

tpaviot commented 3 years ago

I think the set of colors should be generated from tasks and/or resource names. Indeed, with random colors, the Gantt chart colors change each time the solver is called, and it's not easy to compare two different charts. From one Gantt chart to the other, there should be the same color for each task/resource, and because names are unique they can be the basis of the color algorithm.

magic7s commented 3 years ago

@tpaviot I like your idea of keeping the colors consistent. I guess a smaller change would have been to just path through colors to the end user so they could add whatever they want. I'll let you take it from here. Thanks for the quick merge.

tpaviot commented 3 years ago

Yes, both are possible: let the user choose its own colormap, or create a set of colors consistent with task and resources names. That should not be too much work, I keep you posted

dreinon commented 3 years ago

An option would be this one:

colors = ['green', 'blue', 'red', 'yellow', 'grey', 'pink']
N = len(colors) 
task_or_resource_name = 'Hello world'
list_of_ascii_numbers = [str(num) for num in map(ord,task_or_resource_name)]
encoding = int(''.join(list_of_ascii_numbers))
chosen_color = colors[encoding%N]
print(chosen_color)