From 5f021fc4c7f2f626bbba1cb517ae9130b89d6a16 Mon Sep 17 00:00:00 2001
From: cazenave <cazenave@cines.fr>
Date: Mon, 9 Nov 2020 14:18:27 +0100
Subject: [PATCH] add stats

---
 src/app/app.component.html            |  1 +
 src/app/app.module.ts                 |  4 ++-
 src/app/stats/stats.component.html    | 12 +++++++++
 src/app/stats/stats.component.scss    |  0
 src/app/stats/stats.component.spec.ts | 25 +++++++++++++++++++
 src/app/stats/stats.component.ts      | 36 +++++++++++++++++++++++++++
 6 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 src/app/stats/stats.component.html
 create mode 100644 src/app/stats/stats.component.scss
 create mode 100644 src/app/stats/stats.component.spec.ts
 create mode 100644 src/app/stats/stats.component.ts

diff --git a/src/app/app.component.html b/src/app/app.component.html
index 802948410..c9a7668e0 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -28,6 +28,7 @@
     <router-outlet></router-outlet>
    <!--<hr style="border-bottom: 1px solid gray; width: 80%; position: absolute;margin-top: 25%;">
     <p>Test</p>-->
+    <app-stats></app-stats>
   </nb-layout-column>
   <nb-layout-footer>Contact us</nb-layout-footer>
     
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 8a53a0599..50cab74b0 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -43,6 +43,7 @@ import { NbEvaIconsModule } from '@nebular/eva-icons';
 import { AccountComponent } from './account/account.component';
 import { AccountModule } from './account/account.module';
 import { SearchModule} from './search/search.module';
+import { StatsComponent } from './stats/stats.component';
 
 
 @NgModule({
@@ -62,7 +63,8 @@ import { SearchModule} from './search/search.module';
     ElasticsearchComponent,
     PublishApiComponent,
     SearchComponent,
-    AccountComponent
+    AccountComponent,
+    StatsComponent
     ],
   imports: [
     BrowserModule,
diff --git a/src/app/stats/stats.component.html b/src/app/stats/stats.component.html
new file mode 100644
index 000000000..00c0b147c
--- /dev/null
+++ b/src/app/stats/stats.component.html
@@ -0,0 +1,12 @@
+
+<div class="w3-container">
+    <table class="w3-table-all w3-card-4">    
+      <thead style="background-color: #3366ff">    
+        <th style="text-align: center;">Number of Catalogs</th>    
+        <th style="text-align: center;">Number of Datasets</th>    
+      </thead>    
+      <tbody >
+        <tr><td *ngFor="let stat of stats"><strong>{{stat}}</strong></td></tr>
+    </tbody>
+    </table>    
+  </div>
\ No newline at end of file
diff --git a/src/app/stats/stats.component.scss b/src/app/stats/stats.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/app/stats/stats.component.spec.ts b/src/app/stats/stats.component.spec.ts
new file mode 100644
index 000000000..9b880a431
--- /dev/null
+++ b/src/app/stats/stats.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { StatsComponent } from './stats.component';
+
+describe('StatsComponent', () => {
+  let component: StatsComponent;
+  let fixture: ComponentFixture<StatsComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ StatsComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(StatsComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});
diff --git a/src/app/stats/stats.component.ts b/src/app/stats/stats.component.ts
new file mode 100644
index 000000000..fdd8603f5
--- /dev/null
+++ b/src/app/stats/stats.component.ts
@@ -0,0 +1,36 @@
+import { Component, OnInit } from '@angular/core';
+import { HttpClient, HttpHeaders } from '@angular/common/http';
+import { ParseXmlService } from '../services/parse-xml.service';
+
+
+@Component({
+  selector: 'app-stats',
+  templateUrl: './stats.component.html',
+  styleUrls: ['./stats.component.scss']
+})
+export class StatsComponent implements OnInit {
+  
+  public results: string[] = []; 
+  public stats: string[] = [];
+
+  constructor(private parserService: ParseXmlService) { }
+
+  ngOnInit(): void {
+
+      let query1='query=SELECT (COUNT(?s) AS ?triples) WHERE { ?s a <http://www.w3.org/ns/dcat#Catalog> }'
+      this.parserService.getXmlResult(query1).subscribe(data=>{if (data){this.results = []; data.results.bindings.forEach(element => { this.results.push(element);});
+      this.stats.push(this.results[0]["triples"].value)
+
+      let query2='query=SELECT (COUNT(?s) AS ?triples) WHERE { ?s a <http://www.w3.org/ns/dcat#Dataset> }'
+      this.parserService.getXmlResult(query2).subscribe(data=>{if (data){this.results = []; data.results.bindings.forEach(element => { this.results.push(element);});
+      this.stats.push(this.results[0]["triples"].value); }})
+
+      console.log(this.stats);
+    }})
+
+    }
+
+
+
+
+}
-- 
GitLab