From 50128c8c1ea15f927e9012838dd9a4138639e0d2 Mon Sep 17 00:00:00 2001 From: WorthyD Date: Sat, 5 Dec 2020 20:09:49 -0600 Subject: [PATCH] Stuff --- debug.log | 1 + .../_MOCK_ROSTER_ACTIVITY_LIST.ts | 32 ++++++++++++++++- .../activity-bar-chart.component.stories.ts | 2 -- .../clan-activity.service.spec.ts | 16 +++++++++ .../stat-aggregators/clan-activity.service.ts | 32 +++++++++++++++++ .../data/src/lib/stat-aggregators/index.ts | 1 + .../clan-member-activity.component.html | 13 +++++-- .../clan-member-activity.service.ts | 34 +++++++++++-------- 8 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 projects/data/src/lib/stat-aggregators/clan-activity.service.spec.ts create mode 100644 projects/data/src/lib/stat-aggregators/clan-activity.service.ts diff --git a/debug.log b/debug.log index f9ad8fa2..b56da632 100644 --- a/debug.log +++ b/debug.log @@ -15,3 +15,4 @@ [1204/164147.801:ERROR:process_info.cc(329)] VirtualQueryEx: Access is denied. (0x5) [1204/164147.801:ERROR:process_info.cc(556)] ReadMemoryInfo failed [1204/164147.801:ERROR:scoped_process_suspend.cc(40)] NtResumeProcess: An attempt was made to access an exiting process. (0xc000010a) +[1205/195708.258:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3) diff --git a/projects/components/src/lib/clan-roster-activity-table/_MOCK_ROSTER_ACTIVITY_LIST.ts b/projects/components/src/lib/clan-roster-activity-table/_MOCK_ROSTER_ACTIVITY_LIST.ts index da8a4ce4..0cd6ff09 100644 --- a/projects/components/src/lib/clan-roster-activity-table/_MOCK_ROSTER_ACTIVITY_LIST.ts +++ b/projects/components/src/lib/clan-roster-activity-table/_MOCK_ROSTER_ACTIVITY_LIST.ts @@ -3,6 +3,7 @@ import { SECONDS_IN_WEEK, SECONDS_IN_DAY } from '@destiny/models/constants'; import { formatDate } from 'projects/data/src/lib/utility/format-date'; export const MOCK_ROSTER_ACTIVITY = []; export const MOCK_ROSTER_ACTIVITIES = []; +export const MOCK_ROSTER_ACTIVITIES_COMBINE = []; const stats = []; const today = new Date(new Date().setDate(new Date().getDate() + ((2 + 7 - new Date().getDay()) % 7) - 189)); @@ -16,7 +17,6 @@ for (let i = 0; i < 26; i++) { }); } - for (let i = 0; i < 10; i++) { MOCK_ROSTER_ACTIVITY.push({ profile: { @@ -45,3 +45,33 @@ for (let i = 0; i < 10; i++) { activities: stats }); } + +for (let i = 0; i < 10; i++) { + MOCK_ROSTER_ACTIVITIES_COMBINE.push({ + memberProfile: { + profile: { + data: { + userInfo: { + membershipType: 1, + membershipId: i, + displayName: 'User ' + i + }, + dateLastPlayed: '2020-07-31T22:00:00Z', + characterIds: ['2305843009478934569'] + } + }, + id: '1-' + i + // isLoading: false, + // lastNinteyDays: Math.floor(Math.random() * (SECONDS_IN_WEEK * 12) + 1), + // lastMonth: Math.floor(Math.random() * (SECONDS_IN_WEEK * 4) + 1), + // lastWeek: Math.floor(Math.random() * SECONDS_IN_WEEK + 1), + //stats: stats + }, + stats: { + lastNinetyDays: Math.floor(Math.random() * (SECONDS_IN_WEEK * 12) + 1), + lastMonth: Math.floor(Math.random() * (SECONDS_IN_WEEK * 4) + 1), + lastWeek: Math.floor(Math.random() * SECONDS_IN_WEEK + 1), + activities: stats + } + }); +} diff --git a/projects/components/src/lib/shared/charts/activity-bar-chart/activity-bar-chart.component.stories.ts b/projects/components/src/lib/shared/charts/activity-bar-chart/activity-bar-chart.component.stories.ts index f4bac041..978b0bf8 100644 --- a/projects/components/src/lib/shared/charts/activity-bar-chart/activity-bar-chart.component.stories.ts +++ b/projects/components/src/lib/shared/charts/activity-bar-chart/activity-bar-chart.component.stories.ts @@ -6,7 +6,6 @@ import { ActivityBarChartComponent } from './activity-bar-chart.component'; import { withKnobs, select, object, boolean } from '@storybook/addon-knobs'; import { MOCK_GRID_ITEMS, REAL_DATA } from './_MOCK_GRID_ITEMS'; -import { LoadingActivityComponent } from './activity-bar-chart.component-story.stories'; import { MaterialModule } from '../../modules/material.module'; import { LoadingModule } from '../../loading/loading.module'; const events = [MOCK_GRID_ITEMS]; @@ -17,7 +16,6 @@ export default { withKnobs, moduleMetadata({ imports: [ActivityBarChartModule, MaterialModule, LoadingModule], - declarations: [LoadingActivityComponent] }) ] }; diff --git a/projects/data/src/lib/stat-aggregators/clan-activity.service.spec.ts b/projects/data/src/lib/stat-aggregators/clan-activity.service.spec.ts new file mode 100644 index 00000000..0f646e8d --- /dev/null +++ b/projects/data/src/lib/stat-aggregators/clan-activity.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ClanActivityService } from './clan-activity.service'; + +describe('ClanActivityService', () => { + let service: ClanActivityService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ClanActivityService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/projects/data/src/lib/stat-aggregators/clan-activity.service.ts b/projects/data/src/lib/stat-aggregators/clan-activity.service.ts new file mode 100644 index 00000000..dcaf04c5 --- /dev/null +++ b/projects/data/src/lib/stat-aggregators/clan-activity.service.ts @@ -0,0 +1,32 @@ +import { Injectable } from '@angular/core'; +import { ActivityStats, MemberProfile, ClanMember } from 'bungie-models'; +import { forkJoin, from, Observable } from 'rxjs'; +import { map, mergeMap, toArray } from 'rxjs/operators'; +import { ClanMemberRecentActivityService, ProfileService } from '../clan-db'; + +@Injectable({ + providedIn: 'root' +}) +export class ClanActivityService { + readonly CONCURRENT_COUNT = 10; + constructor(private profileService: ProfileService, private memberActivityService: ClanMemberRecentActivityService) {} + + getClanActivityStats(clanId: number, clanMemberProfiles: MemberProfile[]) { + return from(clanMemberProfiles).pipe( + mergeMap((member) => { + return this.getMemberActivityStats(clanId, member); + }, this.CONCURRENT_COUNT) + ); + } + + private getMemberActivityStats(clanId: number, member: MemberProfile): Observable { + return this.memberActivityService.getSerializedProfileActivity(clanId, member).pipe( + map((memberActivityResponse) => { + return { + memberProfile: { profile: member.profile }, + stats: memberActivityResponse + }; + }) + ); + } +} diff --git a/projects/data/src/lib/stat-aggregators/index.ts b/projects/data/src/lib/stat-aggregators/index.ts index 381aef28..a78a12f3 100644 --- a/projects/data/src/lib/stat-aggregators/index.ts +++ b/projects/data/src/lib/stat-aggregators/index.ts @@ -3,3 +3,4 @@ export * from './clan-dungeon.service'; export * from './clan-crucible.service'; export * from './clan-gambit.service'; export * from './clan-roster.service'; +export * from './clan-activity.service'; diff --git a/src/app/clan/clan-member-activity/clan-member-activity.component.html b/src/app/clan/clan-member-activity/clan-member-activity.component.html index 326e1eed..ba9e4eaa 100644 --- a/src/app/clan/clan-member-activity/clan-member-activity.component.html +++ b/src/app/clan/clan-member-activity/clan-member-activity.component.html @@ -12,7 +12,16 @@ - + [isLoading]="clanMemberActivityService.areMembersLoading$ | async" [memberProfilesLoading]="clanMemberActivityService.areMemberProfilesLoading$ | async" (viewMember)="viewMember($event)"> --> + +

+    {{clanMemberActivityService.activityStats | json }}
+  
diff --git a/src/app/clan/clan-member-activity/clan-member-activity.service.ts b/src/app/clan/clan-member-activity/clan-member-activity.service.ts index ca7d49e8..114473cc 100644 --- a/src/app/clan/clan-member-activity/clan-member-activity.service.ts +++ b/src/app/clan/clan-member-activity/clan-member-activity.service.ts @@ -18,13 +18,16 @@ import { getIsMembersProfilesLoaded, getIsMembersProfilesLoading } from '../store/member-profiles/member-profiles.selectors'; -import { ClanMemberRecentActivityService, getMemberProfileId } from '@destiny/data'; +import { ClanActivityService, getMemberProfileId } from '@destiny/data'; + +import * as clanMemberSelectors from '../store/clan-members/clan-members.selectors'; @Injectable() export class ClanMemberActivityService { - constructor(private store: Store, private memberActivityService: ClanMemberRecentActivityService) {} + constructor(private store: Store, private clanActivityService: ClanActivityService) {} isMembersLoaded$ = this.store.pipe(select(getIsMembersProfilesLoaded)); clanId$ = this.store.select(clanIdSelectors.getClanIdState); + clanMembers$ = this.store.select(clanMemberSelectors.getAllMembers); clanMemberProfiles$ = this.store.pipe(select(getAllMembers)); areMembersLoading$ = this.store.pipe(select(getClanMemberActivitiesLoading)); @@ -42,27 +45,30 @@ export class ClanMemberActivityService { activityStats$ = this.preloadedInfo$.pipe( switchMap(([isMemberLoaded, id, clanMembers]) => { this.isLoading = true; - this.memberActivityService.getSerializedProfilesActivity(id, clanMembers).pipe( + return this.clanActivityService.getClanActivityStats(id, clanMembers).pipe( bufferTime(500, undefined, 20), mergeMap((members) => { - this.activityStats = this.activityStats.concat({ - }); + this.activityStats = this.activityStats.concat(members); + return members; }), toArray(), - map((stats) => {}) + map((stats) => { + this.isLoading = false; + }) ); }) ); loadMemberActivity() { - this.isMembersLoaded$ - .pipe( - filter((f) => f === true), - take(1) - ) - .subscribe((x) => { - this.store.dispatch(loadClanMembersActivities()); - }); + // this.isMembersLoaded$ + // .pipe( + // filter((f) => f === true), + // take(1) + // ) + // .subscribe((x) => { + // this.store.dispatch(loadClanMembersActivities()); + // }); + this.activityStats$.pipe(take(1)).subscribe(); } // activityStats$ = this.