438 lines
10 KiB
Markdown
438 lines
10 KiB
Markdown
### get_indicators()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Get the user id.;
|
|
:Fetch all indicators from database that were created by that id.;
|
|
:return indicators;
|
|
stop
|
|
@enduml
|
|
|
|
```
|
|
### get_id()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:db.get_user_id(username);
|
|
:return id;
|
|
stop
|
|
@enduml
|
|
|
|
```
|
|
### get_username()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:db.get_username(u_id);
|
|
:return username;
|
|
stop
|
|
@enduml
|
|
|
|
```
|
|
### save_indicators()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:db.insert_indicator(data=indicator);
|
|
:return indicators;
|
|
stop
|
|
@enduml
|
|
|
|
```
|
|
### is_logged_in()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
if (username in session?) then (no)
|
|
#white/pink:return False;
|
|
stop
|
|
else (yes)
|
|
:get username;
|
|
endif
|
|
if (poll_login_flag?) then (set)
|
|
#white/green:return True;
|
|
stop
|
|
else (not set)
|
|
#white/pink:return False;
|
|
stop
|
|
partition poll_login_flag()
|
|
start
|
|
:get_user_from_cache;
|
|
if (user?) then (yes)
|
|
if (status) then (not logged in)
|
|
:remove from cache;
|
|
#white/pink:return False;
|
|
stop
|
|
else (logged in)
|
|
#white/green:return True;
|
|
stop
|
|
endif
|
|
else (no)
|
|
:Get user from database|
|
|
if (user in database?) then (no)
|
|
#white/pink:return False;
|
|
stop
|
|
else (yes)
|
|
if (status) then (Logged in)
|
|
:add user to cache;
|
|
if (user is guest) then (yes)
|
|
:add suffix to cache;
|
|
note
|
|
suffixes are autogenerated and
|
|
must be tracked to avoid dupes
|
|
end note
|
|
endif
|
|
#white/green:return True;
|
|
stop
|
|
else (not logged in)
|
|
#white/pink:return False;
|
|
stop
|
|
|
|
@enduml
|
|
|
|
```
|
|
### create_unique_guest_name()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Retrieve the used suffixes from the cache;
|
|
if (number of guest_suffixes > self.max_guests) then (no)
|
|
repeat
|
|
:Pick a random suffix.;
|
|
repeat while (Suffix choice already in use?)
|
|
:Return: username appended with suffix;
|
|
stop
|
|
else (yes)
|
|
:return None;
|
|
stop
|
|
|
|
@enduml
|
|
```
|
|
### create_guest()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Request a unique user name;
|
|
if (Username received?) then (no)
|
|
#white/pink:return None;
|
|
stop
|
|
else (yes)
|
|
:Create new user in db;
|
|
:Login user;
|
|
if (Success?) then (true)
|
|
#white/green:Return: username;
|
|
stop
|
|
else (no)
|
|
#white/pink:Return: None;
|
|
stop
|
|
@enduml
|
|
```
|
|
### user_attr_is_taken(attr, val)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Retrieve user status from database.;
|
|
if (result) then (yes)
|
|
:Return: True;
|
|
stop
|
|
else
|
|
:Return: False;
|
|
stop
|
|
@enduml
|
|
```
|
|
|
|
### scramble_text(text)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:scamble text;
|
|
:Return: text;
|
|
@enduml
|
|
```
|
|
### create_new_user_in_db(attrs)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Get the default user template.;
|
|
repeat
|
|
:Modify template with received attribute;
|
|
repeat while (Another attribute?)
|
|
:Drop database index;
|
|
:Insert modified user.;
|
|
:Return: None;
|
|
@enduml
|
|
```
|
|
|
|
### create_new_user()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
if (user exists?) then (yse)
|
|
#white/pink:return False;
|
|
stop
|
|
endif
|
|
if (email exists?) then (yse)
|
|
#white/pink:return False;
|
|
stop
|
|
endif
|
|
:Encrypt password;
|
|
:Create new user in db;
|
|
#green/grey:Return: True;
|
|
stop
|
|
@enduml
|
|
```
|
|
### load_or_create_user()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
if (is logged in?) then (no)
|
|
:create guest;
|
|
if (success?) then (no)
|
|
#pink/grey:Raise error;
|
|
end
|
|
else (yes)
|
|
endif
|
|
else (yes)
|
|
endif
|
|
:Load user data;
|
|
#green/grey:Return: username;
|
|
stop
|
|
@enduml
|
|
```
|
|
### log_in_user(username, password)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Validate password;
|
|
if (success) then (yes)
|
|
:Set the user's status flag as logged in;
|
|
:Record the login time;
|
|
:Return: True;
|
|
stop
|
|
else (no)
|
|
:Return False;
|
|
stop
|
|
@enduml
|
|
```
|
|
### log_out_user(username)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Set the user's status flag as logged out;
|
|
:Record the logout time;
|
|
:Remove the user from the cache;
|
|
:Return: True;
|
|
stop
|
|
@enduml
|
|
```
|
|
### log_out_all_users()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
repeat
|
|
:get data from cache data;
|
|
if (cached data is a user) then (yes)
|
|
:delete data;
|
|
else (no)
|
|
endif
|
|
repeat while(another key?)
|
|
:get logged-in users from the database;
|
|
:drop the default user;
|
|
|
|
repeat
|
|
:set user log-in flag in db;
|
|
repeat while(Loop through all
|
|
logged-in users) is (another user?)
|
|
:Return: None;
|
|
stop
|
|
@enduml
|
|
```
|
|
### load_user_data()
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
if (cache loaded?) then (yes)
|
|
:Return None;
|
|
stop
|
|
else (no)
|
|
endif
|
|
:Get user from db;
|
|
if (success)
|
|
:;
|
|
stop
|
|
@enduml
|
|
```
|
|
### modify_user_data(username, field_name, new_data)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Get the user data from the db;
|
|
:Drop the db id column;
|
|
:Modify the targeted field;
|
|
:Replace the user records in the cache;
|
|
:Delete the old record from the db;
|
|
:Replace the records in the database;
|
|
stop
|
|
@enduml
|
|
```
|
|
### validate_password(username, password)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
if (input invalid) then (yes)
|
|
:Return False;
|
|
stop
|
|
else (no)
|
|
:Request the password from the database;
|
|
if (password?) then (no)
|
|
:Return False;
|
|
stop
|
|
else (yes)
|
|
:Validate password;
|
|
:Return result;
|
|
stop
|
|
@enduml
|
|
```
|
|
### get_chart_view(user_name, prop)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Get user from db;
|
|
if (user?) then (no)
|
|
:Return False;
|
|
stop
|
|
else (yes)
|
|
:Get user from db;
|
|
:Get chartview from user;
|
|
:Return: chartview or specified property;
|
|
stop
|
|
@enduml
|
|
```
|
|
### set_chart_view(user_name, values, specific_property, default_market)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Get user from db;
|
|
if (Specific_property undefined?) then (yes)
|
|
if (Values type is dict?) then (no)
|
|
:raise;
|
|
end
|
|
endif
|
|
if (Values len is 3?) then (no)
|
|
:raise;
|
|
end
|
|
endif
|
|
:Set user['chart view'] = values;
|
|
:return;
|
|
stop
|
|
else (no)
|
|
if (type(specific_property) is str?) then (no)
|
|
:raise;
|
|
end
|
|
endif
|
|
:chartview = user['chart view'];
|
|
if (specific_property == exchange?) then (yes)
|
|
if (default_market?) then (no)
|
|
:raise;
|
|
end
|
|
endif
|
|
:chart_view['market'] = default_market;
|
|
:chart_view['exchange_name'] = values;
|
|
elseif (specific_property == 'timeframe'?) then (yes)
|
|
:chart_view['timeframe'] = values;
|
|
elseif (specific_property == 'market'?) then (yes)
|
|
:chart_view['market'] = values;
|
|
else (raise)
|
|
end
|
|
endif
|
|
:modify_user_data(username=user_name, field_name='chart_views', new_data=str(chart_view));
|
|
stop
|
|
@enduml
|
|
```
|
|
### get_user_from_db(user_name)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:db --> get_rows_where( username == username );
|
|
if (success) then (yse)
|
|
:Return: User;
|
|
stop
|
|
else (no)
|
|
:Return: None;
|
|
stop
|
|
endif
|
|
@enduml
|
|
```
|
|
### get_user_from_cache(user_name)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:get users from cache;
|
|
if (user_name in users?) then (yse)
|
|
:Return: user;
|
|
stop
|
|
else (no)
|
|
:Return: None;
|
|
stop
|
|
endif
|
|
@enduml
|
|
```
|
|
### remove_user_from_cache(user_name)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:get users from cache;
|
|
:del user;
|
|
:save users to cache;
|
|
@enduml
|
|
```
|
|
### add_user_to_cache(user)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:update users in cache with new user;
|
|
:Return: None;
|
|
@enduml
|
|
```
|
|
### add_user_to_cache(user)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:update users in cache with new user;
|
|
:Return: None;
|
|
@enduml
|
|
```
|
|
### update_api_keys(api_keys, exchange, user_name)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Get the user from the database;
|
|
:Get the old api keys dictionary;
|
|
:Add the new keys to the dictionary;
|
|
:Modify the cache and db;
|
|
:Get the old list of configured exchanges;
|
|
:Append the list of configured exchanges;
|
|
:Modify the cache and db;
|
|
:Activate the newly configured exchange;
|
|
@enduml
|
|
```
|
|
### active_exchange(exchange, user_name, cmd)
|
|
```plantuml
|
|
@startuml
|
|
start
|
|
:Get the user from the database;
|
|
:Get the old active_exchanges list;
|
|
if (cmd == 'toggle') then (yes)
|
|
:Remove then add;
|
|
elseif (cmd == 'set') then (yes)
|
|
:Add;
|
|
elseif (cmd == 'remove') then (yes)
|
|
:delete;
|
|
:Modify the cache and db;
|
|
endif
|
|
:Return: None;
|
|
stop
|
|
@enduml
|
|
```
|
|
|