diff --git a/ras/api/modules/pandas.py b/ras/api/modules/pandas.py
index a5bdb25..4284844 100644
--- a/ras/api/modules/pandas.py
+++ b/ras/api/modules/pandas.py
@@ -196,5 +196,35 @@ def countRatings(request):
data = [{"rating": int(rating), "count": int(count)} for rating, count in zip(countratings['rating'], countratings['count'])]
return Response(data)
+ except Exception as e:
+ return JsonResponse({'error': 'An error occurred: {}'.format(str(e))}, safe=False)
+
+# -----------------------------
+# Count EN and NL books
+# -----------------------------
+
+@api_view(['GET'])
+def countEnBooks(request):
+ try:
+ authorization_token = request.headers.get('Authorization')
+ isLoggedIn = isAuthorized(authorization_token)
+
+ if not authorization_token:
+ return JsonResponse({'error': 'No authorization token'}, safe=False)
+
+ if not isLoggedIn:
+ return JsonResponse({'error': 'Unauthorized'}, safe=False)
+
+ if not request.META.get('HTTP_YEAR'):
+ return JsonResponse({'error': 'No year in header'}, safe=False)
+
+ df = filterData(getBooksData(request.headers.get('userid')), request.META.get('HTTP_YEAR'))
+ countbooks = df.groupby('en')['en'].count().reset_index(name="count")
+ countbooks = countbooks.sort_values(by='count', ascending=False)
+ countbooks['lang'] = countbooks['en'].apply(lambda x: 'en' if x == 1 else 'nl')
+ data = [{"lang": lang, "count": int(count)} for lang, count in zip(countbooks['lang'], countbooks['count'])]
+
+ return Response(data)
+
except Exception as e:
return JsonResponse({'error': 'An error occurred: {}'.format(str(e))}, safe=False)
\ No newline at end of file
diff --git a/ras/api/urls.py b/ras/api/urls.py
index 77f4e5c..eb40c4c 100644
--- a/ras/api/urls.py
+++ b/ras/api/urls.py
@@ -11,6 +11,7 @@ urlpatterns = [
path('books/all', getAllBooks),
path('books', getBooksByYear),
path('books/years', getYears),
+ path('books/en', countEnBooks),
path('books/stats', getStats),
path('books/insert', addBook),
path('books/delete', deleteBook),
diff --git a/ras/frontend/src/Functions.js b/ras/frontend/src/Functions.js
index e40acfc..7322463 100644
--- a/ras/frontend/src/Functions.js
+++ b/ras/frontend/src/Functions.js
@@ -22,7 +22,7 @@ export const initDataTable = () => {
search: "",
searchPlaceholder: "Zoeken"
},
- dom: 'rt<"bottom"pl><"clear">',
+ dom: 'rt<"bottom"p><"clear">',
order: []
});
}, 300)
diff --git a/ras/frontend/src/components/Books.js b/ras/frontend/src/components/Books.js
index eca6977..df6b383 100644
--- a/ras/frontend/src/components/Books.js
+++ b/ras/frontend/src/components/Books.js
@@ -10,8 +10,7 @@ const Books = (props) => {
const yearbooks = await data.getBooksPerYearPerGenres(props.year);
if(yearbooks){
- const ratings = await data.getAvgRatings(props.year);
- charts.initChart(yearbooks, ratings, props.year);
+ charts.initChart(yearbooks, props.year);
}
}
diff --git a/ras/frontend/src/components/Charts.js b/ras/frontend/src/components/Charts.js
index 792b5f9..c6e771b 100644
--- a/ras/frontend/src/components/Charts.js
+++ b/ras/frontend/src/components/Charts.js
@@ -1,4 +1,4 @@
-export const initChart = (data, ratings, year) => {
+export const initChart = (data, year) => {
/*
----------------------------------
@@ -9,8 +9,7 @@ export const initChart = (data, ratings, year) => {
var genres = [];
var colors = [
- // '#696ffc', '#7596fa', '#92adfe', '#abc0ff'
- '#404e67', '#01a9ac', '#64c5b1', '#1ABB9C'
+ '#405181', '#01a9ac', '#64c5b1', '#1ABB9C'
]
var dataSet = [];
@@ -54,39 +53,6 @@ export const initChart = (data, ratings, year) => {
})
}
- /*
- ----------------------------------
- Avarage ratings per month
- ----------------------------------
- */
-
- var avgRatings = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
-
- for (var j = 0; j < 12; j++) {
-
- if (j < 9) {
- var month = "0" + (j + 1)
- } else {
- month = (j + 1)
- }
-
- for (var i = 0; i < ratings.length; i++) {
- if (ratings[i].date == month + '-' + year) {
- avgRatings[j] = ratings[i].rating;
- }
- }
- }
-
- dataSet.push({
- label: 'Gemiddelde beoordeling',
- data: avgRatings,
- backgroundColor: '#ffa500',
- borderColor: '#ffa500',
- tension: 0.4,
- type: 'line',
- order: 1
- })
-
/*
----------------------------------
Stacked bar chart
@@ -208,7 +174,7 @@ export const initDoughnut = (data) => {
label: '# of Tomatoes',
data: counts,
backgroundColor: [
- '#404e67', '#01a9ac', '#64c5b1', '#1ABB9C'
+ '#405181', '#01a9ac', '#64c5b1', '#1ABB9C'
],
borderWidth: 0,
borderColor: '#1f2940',
diff --git a/ras/frontend/src/components/DataTables.css b/ras/frontend/src/components/DataTables.css
index 5c1e762..c2adf2c 100644
--- a/ras/frontend/src/components/DataTables.css
+++ b/ras/frontend/src/components/DataTables.css
@@ -8,7 +8,7 @@
#DataTable td {
color: #333;
- font-size: 12px;
+ font-size: 14px;
height: 40px;
font-weight: 300;
vertical-align: middle;
@@ -56,7 +56,7 @@
padding: 15px 20px;
border-bottom: 1px solid #efefef;
font-weight: 600;
- font-size: 12px;
+ font-size: 14px;
color:#000000;
}
@@ -72,19 +72,6 @@
padding:14px;
}
-#DataTable .openAlarm .pictogram {
- /* display: inline-block;
- padding: 0 0 0 0;
- margin: 10px 10px 10px 10px;
- background: rgb(255,0,0); */
- display: inline-block;
- margin: 10px 10px 10px 10px;
- background: rgb(255,0,0);
- box-shadow: rgba(0, 0, 0, 0.2) 0px 3px 1px -2px, rgba(0, 0, 0, 0.14) 0px 2px 2px 0px, rgba(0, 0, 0, 0.12) 0px 1px 5px 0px;
- border-radius: 100%;
- padding: 5px;
-}
-
#DataTable tbody td:first-child{
padding: 0rem;
}
@@ -99,20 +86,6 @@
border-bottom: solid 1px #f8f8f8 !important;
}
-#DataTable .openAlarm td{
- padding:10px;
- color: #000000;
- font-size: 14px;
- height: 45px;
- font-weight: 400;
- vertical-align: middle;
- border-top: 1px solid #efefef;
-}
-
-#DataTable .openAlarm:first-child td{
- border-top:none;
-}
-
.DataTable_Container {
margin: 0px 2.5rem 0px 2.5rem;
}
@@ -138,37 +111,10 @@
margin-bottom: 0;
}
-.DataTable_Container .historyAlarm .pictogram {
- /* display: inline-block;
- padding: 0 0 0 0;
- margin: 10px 10px 10px 10px;
- background: rgb(255,0,0); */
- display: inline-block;
- margin: 10px 10px 10px 10px;
- background: rgb(255,0,0);
- box-shadow: rgba(0, 0, 0, 0.2) 0px 3px 1px -2px, rgba(0, 0, 0, 0.14) 0px 2px 2px 0px, rgba(0, 0, 0, 0.12) 0px 1px 5px 0px;
- border-radius: 100%;
- padding: 5px;
-}
-
.DataTable_Container .table tbody td:first-child{
padding: 0rem;
}
-.DataTable_Container .historyAlarm td{
- padding:10px;
- color: #000000;
- font-size: 14px;
- height: 45px;
- font-weight: 100;
- vertical-align: middle;
- border-top: 1px solid #efefef;
-}
-
-.DataTable_Container .historyAlarm:first-child td{
- border-top:none;
-}
-
.DataTable_Container .dataTables_length{
padding: 20px 0;
}
@@ -218,7 +164,7 @@
}
.dataTables_wrapper .dataTables_paginate{
- float:right;
+ text-align: center;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
@@ -233,7 +179,7 @@
color: #333 !important;
border: 1px solid transparent;
border-radius: 2px;
- font-size: 13px;
+ font-size: 14px;
}
.showHead thead{
diff --git a/ras/frontend/src/components/Readed.js b/ras/frontend/src/components/Readed.js
index f73e0fd..2e71193 100644
--- a/ras/frontend/src/components/Readed.js
+++ b/ras/frontend/src/components/Readed.js
@@ -1,30 +1,35 @@
import React, { useEffect, useState } from 'react';
-import '../components/DataTables.css';
-import 'flag-icon-css/css/flag-icons.min.css';
-import DataTable from 'datatables.net-dt';
+import './DataTables.css';
+import * as moment from 'moment';
+moment.locale('nl');
const Readed = (props) => {
const [books, setBooks] = useState([]);
const getData = async () => {
- const data = await import("./Data.js");
+ const [data, functions] = await Promise.all([
+ import("../components/Data.js"),
+ import("../Functions.js")
+ ])
+
const yearbooks = await data.getBooksByYear(props.year);
- if(yearbooks){
- setBooks(yearbooks);
- }
- setTimeout(() => {
- let table = new DataTable('#DataTable');
- table.destroy();
+ var months = [];
- table = new DataTable('#DataTable', {
- language: {
- url: 'https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Dutch.json'
- },
- dom: 'rt<"bottom"p><"clear">',
- order: []
+ for(var i = 1; i < 13; i++){
+ months[i] = [];
+
+ yearbooks.forEach(book => {
+ console.log(moment(book.readed).format("M"), i);
+ if(moment(book.readed).format("M") == i){
+ months[i].push(book);
+ }
});
- }, 1000)
+ }
+
+ setBooks(yearbooks);
+
+ functions.initDataTable();
}
useEffect(() => {
@@ -33,32 +38,64 @@ const Readed = (props) => {
return (
-
-
-
-
-
-
- {books.map((book, i) => {
- var code = book.country_code.toLowerCase();
- return (
- Book
- Author
- Genre
- Ratings
-
-
- )
- })}
-
- {book.name}
- {book.author}
- {book.genre}
- {book.rating}
-
+
+
+
+
+
+
+ {books.map((book, i) => {
+ var dotcolor = '';
+
+ if(book.genre === "Thriller"){
+ dotcolor = '#404e67';
+ }else if (book.genre === "Roman"){
+ dotcolor = '#01a9ac';
+ }else if(book.genre === 'Non-fictie'){
+ dotcolor = '#64c5b1';
+ }else{
+ dotcolor = '#1ABB9C';
+ }
+
+ return (
+ Gelezen boeken
+
+
+
+
+
+ )
+ })}
+
+
+
+
+ {book.rating}
+ {moment(book.readed).format("MMMM")}
+
+
+
+
Gelezen boeken | -- | - | - |
---|---|---|---|
-
-
- {book.name}
-
- {book.author}
- |
- {book.rating} | -{moment(book.readed).format("MMMM")} | -- - | -