Models
current_star: GalaxyStar | None
property
¶
The star of this user in the :class:Galaxy
.
Only take into account the most recent active galaxy.
Returns:
Type | Description |
---|---|
GalaxyStar | None
|
The star of this user if there is an active Galaxy |
GalaxyStar | None
|
and this user is a citizen of it, else |
Club
¶
Bases: Model
The Club class, made as a tree to allow nice tidy organization.
check_loop()
¶
Raise a validation error when a loop is found within the parent list.
Source code in club/models.py
is_owned_by(user)
¶
can_be_edited_by(user)
¶
can_be_viewed_by(user)
¶
Method to see if that object can be seen by the given user.
get_membership_for(user)
¶
Return the current membership the given user.
Note
The result is cached.
Source code in club/models.py
User
¶
Bases: AbstractBaseUser
Defines the base user class, useable in every app.
This is almost the same as the auth module AbstractUser since it inherits from it, but some fields are required, and the username is generated automatically with the name of the user (see generate_username()).
Added field: nick_name, date_of_birth Required fields: email, first_name, last_name, date_of_birth
cached_groups: list[Group]
property
¶
Get the list of groups this user is in.
The result is cached for the default duration (should be 5 minutes)
Returns: A list of all the groups this user is in.
is_in_group(*, pk=None, name=None)
¶
Check if this user is in the given group. Either a group id or a group name must be provided. If both are passed, only the id will be considered.
The group will be fetched using the given parameter. If no group is found, return False. If a group is found, check if this user is in the latter.
Returns:
Type | Description |
---|---|
bool
|
True if the user is the group, else False |
Source code in core/models.py
age()
¶
Return the age this user has the day the method is called. If the user has not filled his age, return 0.
Source code in core/models.py
get_full_name()
¶
get_short_name()
¶
get_display_name()
¶
Returns the display name of the user.
A nickname if possible, otherwise, the full name.
get_age()
¶
get_family(godfathers_depth=4, godchildren_depth=4)
¶
Get the family of the user, with the given depth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
godfathers_depth
|
NonNegativeInt
|
The number of generations of godfathers to fetch |
4
|
godchildren_depth
|
NonNegativeInt
|
The number of generations of godchildren to fetch |
4
|
Returns:
Type | Description |
---|---|
set[through]
|
A list of family relationships in this user's family |
Source code in core/models.py
email_user(subject, message, from_email=None, **kwargs)
¶
Sends an email to this User.
generate_username()
¶
Generates a unique username based on the first and last names.
For example: Guy Carlier gives gcarlier, and gcarlier1 if the first one exists.
Returns:
Type | Description |
---|---|
str
|
The generated username. |
Source code in core/models.py
is_owner(obj)
¶
Determine if the object is owned by the user.
Source code in core/models.py
can_edit(obj)
¶
Determine if the object can be edited by the user.
Source code in core/models.py
can_view(obj)
¶
Determine if the object can be viewed by the user.
Source code in core/models.py
clubs_with_rights()
¶
The list of clubs where the user has rights
GalaxyStar
¶
Bases: Model
Define a star (vertex -> user) in the galaxy graph.
Store a reference to its owner citizen.
Stars are linked to each others through the :class:GalaxyLane
model.
Each GalaxyStar has a mass which push it towards the center of the galaxy. This mass is proportional to the number of pictures the owner of the star is tagged on.
GalaxyLane
¶
Bases: Model
Define a lane (edge -> link between galaxy citizen) in the galaxy map.
Store a reference to both its ends and the distance it covers. Score details between citizen owning the stars is also stored here.
StarDict
¶
Bases: TypedDict
GalaxyDict
¶
Bases: TypedDict
RelationScore
¶
Bases: NamedTuple
Galaxy
¶
Bases: Model
The Galaxy, a graph linking the active users between each others.
The distance between two users is given by a relation score which takes into account a few parameter like the number of pictures they are both tagged on, the time during which they were in the same clubs and whether they are in the same family.
The citizens of the Galaxy are represented by :class:GalaxyStar
and their relations by :class:GalaxyLane
.
Several galaxies can coexist. In this case, only the most recent active one shall usually be taken into account. This is useful to keep the current galaxy while generating a new one and swapping them only at the very end.
Please take into account that generating the galaxy is a very expensive
operation. For this reason, try not to call the :meth:rule
method more
than once a day in production.
To quickly access to the state of a galaxy, use the :attr:state
attribute.
compute_user_score(user)
classmethod
¶
Compute an individual score for each citizen.
It will later be used by the graph algorithm to push higher scores towards the center of the galaxy.
Idea: This could be added to the computation:
- Forum posts
- Picture count
- Counter consumption
- Barman time
- ...
Source code in galaxy/models.py
query_user_score(user)
classmethod
¶
Get the individual score of the given user in the galaxy.
Source code in galaxy/models.py
compute_users_score(user1, user2)
classmethod
¶
Compute the relationship scores of the two given users.
The computation is done with the following fields :
- family: if they have some godfather/godchild relation
- pictures: in how many pictures are both tagged
- clubs: during how many days they were members of the same clubs
Source code in galaxy/models.py
compute_users_family_score(user1, user2)
classmethod
¶
Compute the family score of the relation between the given users.
This takes into account mutual godfathers.
Returns:
Type | Description |
---|---|
int
|
366 if user1 is the godfather of user2 (or vice versa) else 0 |
Source code in galaxy/models.py
compute_users_pictures_score(user1, user2)
classmethod
¶
Compute the pictures score of the relation between the given users.
The pictures score is obtained by counting the number
of :class:Picture
in which they have been both identified.
This score is then multiplied by 2.
Returns:
Type | Description |
---|---|
int
|
The number of pictures both users have in common, times 2 |
Source code in galaxy/models.py
compute_users_clubs_score(user1, user2)
classmethod
¶
Compute the clubs score of the relation between the given users.
The club score is obtained by counting the number of days
during which the memberships (see :class:club.models.Membership
)
of both users overlapped.
For example, if user1 was a member of Unitec from 01/01/2020 to 31/12/2021 (two years) and user2 was a member of the same club from 01/01/2021 to 31/12/2022 (also two years, but with an offset of one year), then their club score is 365.
Returns:
Type | Description |
---|---|
int
|
the number of days during which both users were in the same club |
Source code in galaxy/models.py
scale_distance(value)
classmethod
¶
Given a numeric value, return a scaled value which can be used in the Galaxy's graphical interface to set the distance between two stars.
Returns:
Type | Description |
---|---|
int
|
the scaled value usable in the Galaxy's 3d graph |
Source code in galaxy/models.py
rule(picture_count_threshold=10)
¶
Main function of the Galaxy.
Iterate over all the rulable users to promote them to citizens. A citizen is a user who has a corresponding star in the Galaxy. Also build up the lanes, which are the links between the different citizen.
Users who can be ruled are defined with the picture_count_threshold
:
all users who are identified in a strictly lower number of pictures
won't be promoted to citizens.
This does very effectively limit the quantity of computing to do
and only includes users who have had a minimum of activity.
This method still remains very expensive, so think thoroughly before you call it, especially in production.
:param picture_count_threshold: the minimum number of picture to have to be included in the galaxy
Source code in galaxy/models.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
|
make_state()
¶
Compute JSON structure to send to 3d-force-graph: https://github.com/vasturiano/3d-force-graph/.