Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Fjern ZipCodeRegion #514

Open
Rotendahl opened this issue Apr 10, 2020 · 1 comment
Open

[Refactor] Fjern ZipCodeRegion #514

Rotendahl opened this issue Apr 10, 2020 · 1 comment

Comments

@Rotendahl
Copy link
Contributor

Hvad skal refactors og hvorfor?
Lige nu bygger bruger vi vores egen mapping mellem en adresses postnummer og region.
Eftersom at vi har et region felt på afdelinger kan vi ligeså godt bare bruge det og slette zipcode region så vi ikke skal have en liste af (postnumre, region) for hele danmark i tabellen.

Det kræver at vi omskriver denne del af koden

# generate daily region statistics
regions = ("DK01", "DK02", "DK03", "DK04", "DK05")
for region in regions:
dailyStatisticsRegion = DailyStatisticsRegion()
zipsInRegion = ZipcodeRegion.objects.filter(region=region).values_list(
"zipcode", flat=True
) # There are no easy foreing key to identify region
dailyStatisticsRegion.timestamp = timestamp
dailyStatisticsRegion.region = region
# No unions - since unions may span regions
dailyStatisticsRegion.departments = (
Department.objects.annotate()
.filter(address__zipcode__in=zipsInRegion)
.count()
)
dailyStatisticsRegion.active_activities = Activity.objects.filter(
department__address__zipcode__in=zipsInRegion,
start_date__lte=timestamp,
end_date__gte=timestamp,
).count()
dailyStatisticsRegion.activities = Activity.objects.filter(
department__address__zipcode__in=zipsInRegion
).count()
dailyStatisticsRegion.current_activity_participants = (
Person.objects.filter(
member__activityparticipant__activity__start_date__lte=timestamp,
member__activityparticipant__activity__end_date__gte=timestamp,
member__activityparticipant__activity__department__address__zipcode__in=zipsInRegion,
)
.distinct()
.count()
)
dailyStatisticsRegion.activity_participants = ActivityParticipant.objects.filter(
activity__department__address__zipcode__in=zipsInRegion
).count()
dailyStatisticsRegion.members = 0 # TODO: to loosely defined now
dailyStatisticsRegion.waitinglist = (
Person.objects.filter(
waitinglist__department__address__zipcode__in=zipsInRegion
)
.distinct()
.count()
)
dailyStatisticsRegion.payments = Payment.objects.filter(
activity__department__address__zipcode__in=zipsInRegion,
refunded_dtm=None,
confirmed_dtm__isnull=False,
).aggregate(sum=Coalesce(Sum("amount_ore"), 0))["sum"]
dailyStatisticsRegion.volunteers_male = (
Person.objects.filter(
volunteer__department__address__zipcode__in=zipsInRegion,
gender=Person.MALE,
)
.distinct()
.count()
)
dailyStatisticsRegion.volunteers_female = (
Person.objects.filter(
volunteer__department__address__zipcode__in=zipsInRegion,
gender=Person.FEMALE,
)
.distinct()
.count()
)
dailyStatisticsRegion.volunteers = (
dailyStatisticsRegion.volunteers_male
+ dailyStatisticsRegion.volunteers_female
)
dailyStatisticsRegion.save()

Så den er i stil med https://github.com/CodingPirates/forenings_medlemmer/blob/master/members/models/statistics/department_statistic.py
Så kan vi også få skrevet tests i samme omgang.

@JakobLibak JakobLibak added this to the Opdatering af datamodel milestone Apr 11, 2020
@rasmusselsmark
Copy link
Contributor

Afhænger af #874

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants