Skip to content

Commit

Permalink
feat(data): update data module, add new mock data (#1960)
Browse files Browse the repository at this point in the history
  • Loading branch information
denStrigo committed Jan 8, 2019
1 parent 773c14e commit 47d232b
Show file tree
Hide file tree
Showing 53 changed files with 635 additions and 256 deletions.
10 changes: 9 additions & 1 deletion src/app/@core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { of as observableOf } from 'rxjs';

import { throwIfAlreadyLoaded } from './module-import-guard';
import { DataModule } from './data/data.module';
import { AnalyticsService } from './utils/analytics.service';
import {
AnalyticsService,
LayoutService,
PlayerService,
StateService,
} from './utils';

const socialLinks = [
{
Expand Down Expand Up @@ -71,6 +76,9 @@ export const NB_CORE_PROVIDERS = [
provide: NbRoleProvider, useClass: NbSimpleRoleProvider,
},
AnalyticsService,
LayoutService,
PlayerService,
StateService,
];

@NgModule({
Expand Down
28 changes: 28 additions & 0 deletions src/app/@core/data/country-order.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';

@Injectable()
export class CountryOrderService {

private countriesCategories = [
'Sofas',
'Furniture',
'Lighting',
'Tables',
'Textiles',
];
private countriesCategoriesLength = this.countriesCategories.length;
private generateRandomData(nPoints: number): number[] {
return Array.from(Array(nPoints)).map(() => {
return Math.round(Math.random() * 20);
});
}

getCountriesCategories(): Observable<string[]> {
return observableOf(this.countriesCategories);
}

getCountriesCategoriesData(): Observable<number[]> {
return observableOf(this.generateRandomData(this.countriesCategoriesLength));
}
}
22 changes: 16 additions & 6 deletions src/app/@core/data/data.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { CommonModule } from '@angular/common';

import { UserService } from './users.service';
import { ElectricityService } from './electricity.service';
import { StateService } from './state.service';
import { SmartTableService } from './smart-table.service';
import { PlayerService } from './player.service';
import { UserActivityService } from './user-activity.service';
import { OrdersChartService } from './orders-chart.service';
import { ProfitChartService } from './profit-chart.service';
Expand All @@ -15,14 +13,19 @@ import { EarningService } from './earning.service';
import { OrdersProfitChartService } from './orders-profit-chart.service';
import { TrafficBarService } from './traffic-bar.service';
import { ProfitBarAnimationChartService } from './profit-bar-animation-chart.service';
import { LayoutService } from './layout.service';
import { TemperatureHumidityService } from './temperature-humidity.service';
import { SolarService } from './solar.service';
import { TrafficChartService } from './traffic-chart.service';
import { StatsBarService } from './stats-bar.service';
import { CountryOrderService } from './country-order.service';
import { StatsProgressBarService } from './stats-progress-bar.service';
import { VisitorsAnalyticsService } from './visitors-analytics.service';
import { SecurityCamerasService } from './security-cameras.service';

const SERVICES = [
UserService,
ElectricityService,
StateService,
SmartTableService,
PlayerService,
UserActivityService,
OrdersChartService,
ProfitChartService,
Expand All @@ -32,7 +35,14 @@ const SERVICES = [
OrdersProfitChartService,
TrafficBarService,
ProfitBarAnimationChartService,
LayoutService,
TemperatureHumidityService,
SolarService,
TrafficChartService,
StatsBarService,
CountryOrderService,
StatsProgressBarService,
VisitorsAnalyticsService,
SecurityCamerasService,
];

@NgModule({
Expand Down
52 changes: 48 additions & 4 deletions src/app/@core/data/electricity.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';

class Month {
month: string;
delta: string;
down: boolean;
kWatts: string;
cost: string;
}

export class Electricity {
title: string;
active?: boolean;
months: Month[];
}

export class ElectricityChart {
label: string;
value: number;
}

@Injectable()
export class ElectricityService {

private data = [
private listData: Electricity[] = [
{
title: '2015',
months: [
Expand Down Expand Up @@ -58,11 +78,35 @@ export class ElectricityService {
},
];

private chartPoints = [
490, 490, 495, 500,
505, 510, 520, 530,
550, 580, 630, 720,
800, 840, 860, 870,
870, 860, 840, 800,
720, 200, 145, 130,
130, 145, 200, 570,
635, 660, 670, 670,
660, 630, 580, 460,
380, 350, 340, 340,
340, 340, 340, 340,
340, 340, 340,
];

chartData: ElectricityChart[];

constructor() {
this.chartData = this.chartPoints.map((p, index) => ({
label: (index % 5 === 3) ? `${Math.round(index / 5)}` : '',
value: p,
}));
}

getListData(): Observable<Electricity[]> {
return observableOf(this.listData);
}

// TODO: observables
getData() {
return this.data;
getChartData(): Observable<ElectricityChart[]> {
return observableOf(this.chartData);
}
}
2 changes: 1 addition & 1 deletion src/app/@core/data/profit-bar-animation-chart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ProfitBarAnimationChartService {
return Array.from(Array(nPoints));
}

getChartData(): Observable<{ firstLine: number[]; secondLine: number[] }> {
getChartData(): Observable<{ firstLine: number[]; secondLine: number[]; }> {
return observableOf(this.data);
}
}
34 changes: 34 additions & 0 deletions src/app/@core/data/security-cameras.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';

export class Camera {
title: string;
source: string;
}

@Injectable()
export class SecurityCamerasService {

private cameras: Camera[] = [
{
title: 'Camera #1',
source: 'assets/images/camera1.jpg',
},
{
title: 'Camera #2',
source: 'assets/images/camera2.jpg',
},
{
title: 'Camera #3',
source: 'assets/images/camera3.jpg',
},
{
title: 'Camera #4',
source: 'assets/images/camera4.jpg',
},
];

getCamerasData(): Observable<Camera[]> {
return observableOf(this.cameras);
}
}
11 changes: 11 additions & 0 deletions src/app/@core/data/solar.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';

@Injectable()
export class SolarService {
private value = 42;

getSolarData(): Observable<number> {
return observableOf(this.value);
}
}
15 changes: 15 additions & 0 deletions src/app/@core/data/stats-bar.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';

@Injectable()
export class StatsBarService {

private statsBarData: number[] = [
300, 520, 435, 530,
730, 620, 660, 860,
];

getStatsBarData(): Observable<number[]> {
return observableOf(this.statsBarData);
}
}
37 changes: 37 additions & 0 deletions src/app/@core/data/stats-progress-bar.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';

export class ProgressInfo {
title: string;
value: number;
activeProgress: number;
description: string;
}

@Injectable()
export class StatsProgressBarService {
private progressInfoData: ProgressInfo[] = [
{
title: 'Today’s Profit',
value: 572900,
activeProgress: 70,
description: 'Better than last week (70%)',
},
{
title: 'New Orders',
value: 6378,
activeProgress: 30,
description: 'Better than last week (30%)',
},
{
title: 'New Comments',
value: 200,
activeProgress: 55,
description: 'Better than last week (55%)',
},
];

getProgressInfoData(): Observable<ProgressInfo[]> {
return observableOf(this.progressInfoData);
}
}
32 changes: 32 additions & 0 deletions src/app/@core/data/temperature-humidity.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';

export class Temperature {
value: number;
min: number;
max: number;
}

@Injectable()
export class TemperatureHumidityService {

private temperatureDate: Temperature = {
value: 24,
min: 12,
max: 30,
};

private humidityDate: Temperature = {
value: 87,
min: 0,
max: 100,
};

getTemperatureData(): Observable<Temperature> {
return observableOf(this.temperatureDate);
}

getHumidityData(): Observable<Temperature> {
return observableOf(this.humidityDate);
}
}
16 changes: 16 additions & 0 deletions src/app/@core/data/traffic-chart.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';


@Injectable()
export class TrafficChartService {

private data: number[] = [
300, 520, 435, 530,
730, 620, 660, 860,
];

getTrafficChartData(): Observable<number[]> {
return observableOf(this.data);
}
}
37 changes: 16 additions & 21 deletions src/app/@core/data/user-activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export class UserActive {
export class UserActivityService {

private getRandom = (roundTo: number) => Math.round(Math.random() * roundTo);
private generateUserActivityRandomData(date) {
return {
date,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
}

data = {};

Expand All @@ -26,38 +34,25 @@ export class UserActivityService {

private getDataWeek(): UserActive[] {
return this.periods.getWeeks().map((week) => {
return {
date: week,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
return this.generateUserActivityRandomData(week);
});
}

private getDataMonth(): UserActive[] {
const date = new Date();
const days = date.getDate();
const month = this.periods.getMonths()[date.getMonth()];
const currentDate = new Date();
const days = currentDate.getDate();
const month = this.periods.getMonths()[currentDate.getMonth()];

return Array.from(Array(days)).map((_, index) => {
return {
date: `${index + 1} ${month}`,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
const date = `${index + 1} ${month}`;

return this.generateUserActivityRandomData(date);
});
}

private getDataYear(): UserActive[] {
return this.periods.getYears().map((year) => {
return {
date: year,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
return this.generateUserActivityRandomData(year);
});
}

Expand Down

0 comments on commit 47d232b

Please sign in to comment.