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

Add mock data #1960

Merged
merged 6 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
20 changes: 14 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,18 @@ 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';

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

@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);
}
}
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
Loading