removed maths section from front-end #24

Merged
Sarsoo merged 1 commits from maths-removal into master 2021-03-20 19:04:09 +00:00
6 changed files with 6 additions and 286 deletions

View File

@ -245,6 +245,10 @@ def test():
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'service.json'
subprocess.check_call("python -u -m unittest discover -s tests", shell=True)
def run():
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'service.json'
subprocess.check_call("python main.api.py", shell=True)
if __name__ == '__main__':
console = Admin()
if len(sys.argv) > 1:

View File

@ -9,6 +9,7 @@ repository = "https://github.com/Sarsoo/Music-Tools"
[tool.poetry.scripts]
test = 'admin:test'
start = 'admin:run'
[tool.poetry.dependencies]
python = "^3.8"

View File

@ -1,265 +0,0 @@
import React, { Component } from "react";
const axios = require('axios');
import showMessage from "../Toast.js";
import BarChart from "./BarChart.js";
import PieChart from "./PieChart.js";
class Count extends Component {
constructor(props){
super(props);
this.state = {
playlists: [],
isLoading: true,
chartPlaylists: []
}
this.getPlaylists();
this.handleCheckbox = this.handleCheckbox.bind(this);
}
getPlaylists(){
axios.get('/api/playlists')
.then((response) => {
var playlists = [];
var playlist_in;
for(playlist_in of response.data.playlists) {
if(playlist_in['lastfm_stat_last_refresh'] != undefined){
playlists.push(playlist_in);
}
}
playlists.sort(function(a, b){
return b['lastfm_stat_count'] - a['lastfm_stat_count'];
});
this.setState({
playlists: playlists,
isLoading: false
});
})
.catch((error) => {
console.log(error);
showMessage(`error getting playlists (${error.response.status})`);
});
}
handleCheckbox(event) {
if(event.target.checked == true){
var playlists = this.state.chartPlaylists.slice();
playlists.push(event.target.name);
this.setState({chartPlaylists: playlists});
}else{
var playlists = this.state.chartPlaylists.slice();
playlists.splice(playlists.indexOf(event.target.name), 1);
this.setState({chartPlaylists: playlists});
}
}
getPieChartTrackData(){
var playlists = this.state.chartPlaylists;
if(playlists.length > 0){
var data = playlists.map((entry) => {
var i;
for(i = 0; i < this.state.playlists.length; i++){
var playlist = this.state.playlists[i];
if(playlist.name == entry){
return {
"label": playlist.name,
"value": playlist.lastfm_stat_percent
}
}
}
console.log(`${entry} not found`);
});
var total = data.reduce((total, value) => {
return total + value.value;
}, 0);
data.sort((a, b) => {
if(a.value > b.value) { return -1; }
if(a.value < b.value) { return 1; }
return 0;
})
if(total > 100){
return [{
'label': 'over 100%',
'value': 100
}];
}else{
data.push({
'label': 'other',
'value': 100 - total
})
}
return data;
}else{
return [{
'label': 'no selection',
'value': 100
}];
}
}
getPieChartAlbumData(){
var playlists = this.state.chartPlaylists;
if(playlists.length > 0){
var data = playlists.map((entry) => {
var i;
for(i = 0; i < this.state.playlists.length; i++){
var playlist = this.state.playlists[i];
if(playlist.name == entry){
return {
"label": playlist.name,
"value": playlist.lastfm_stat_album_percent
}
}
}
console.log(`${entry} not found`);
});
var total = data.reduce((total, value) => {
return total + value.value;
}, 0);
data.sort((a, b) => {
if(a.value > b.value) { return -1; }
if(a.value < b.value) { return 1; }
return 0;
})
if(total > 100){
return [{
'label': 'over 100%',
'value': 100
}];
}else{
data.push({
'label': 'other',
'value': 100 - total
})
}
return data;
}else{
return [{
'label': 'no selection',
'value': 100
}];
}
}
getPieChartArtistData(){
var playlists = this.state.chartPlaylists;
if(playlists.length > 0){
var data = playlists.map((entry) => {
var i;
for(i = 0; i < this.state.playlists.length; i++){
var playlist = this.state.playlists[i];
if(playlist.name == entry){
return {
"label": playlist.name,
"value": playlist.lastfm_stat_artist_percent
}
}
}
console.log(`${entry} not found`);
});
var total = data.reduce((total, value) => {
return total + value.value;
}, 0);
data.sort((a, b) => {
if(a.value > b.value) { return -1; }
if(a.value < b.value) { return 1; }
return 0;
})
if(total > 100){
return [{
'label': 'over 100%',
'value': 100
}];
}else{
data.push({
'label': 'other',
'value': 100 - total
})
}
return data;
}else{
return [{
'label': 'no selection',
'value': 100
}];
}
}
render() {
var data = this.state.playlists.map((entry) => {
return {
"label": entry.name,
"value": entry.lastfm_stat_count
};
})
var table = <div>
<table className="app-table max-width">
<thead>
<tr>
<th colSpan='3'>
<h1 className="ui-text center-text text-no-select">scrobble counts</h1>
</th>
</tr>
</thead>
<tbody>
{this.state.playlists.map((entry) => <Row name={entry.name} count={entry.lastfm_stat_count} percent={entry.lastfm_stat_percent} handler={this.handleCheckbox} key={entry.name}/>)}
</tbody>
</table>
<BarChart data={data} title='scrobbles'/>
<PieChart data={this.getPieChartTrackData()} title='genres'/>
<PieChart data={this.getPieChartAlbumData()} title='genres'/>
<PieChart data={this.getPieChartArtistData()} title='genres'/>
</div>;
const loadingMessage = <p className="center-text">loading...</p>;
return this.state.isLoading ? loadingMessage : table;
}
}
function Row(props){
return <tr>
<td className="ui-text center-text text-no-select" style={{width: '50%'}}>{props.name}</td>
<td className="ui-text center-text text-no-select"><b>{props.count.toLocaleString()} / {props.percent}%</b></td>
<td className="ui-text center-text text-no-select" style={{width: '20px'}}><input type="checkbox" name={props.name} onChange={props.handler} /></td>
</tr>;
}
export default Count;

View File

@ -1,15 +0,0 @@
import React, { Component } from "react";
import { BrowserRouter as Route} from "react-router-dom";
import Count from "./Count.js";
class Maths extends Component {
render() {
return <Route path={`${this.props.match.url}/count`} render={(props) => <Count {...props} name={this.props.match.params.name}/>} />;
}
}
export default Maths;

View File

@ -27,7 +27,6 @@ import { Build, PieChart, QueueMusic, ExitToApp, AccountCircle, KeyboardBackspac
const axios = require('axios');
const LazyIndex = React.lazy(() => import("./Index/Index"))
const LazyMaths = React.lazy(() => import("./Maths/MathsRouter"))
const LazyPlaylists = React.lazy(() => import("./Playlist/AllPlaylistsRouter"))
const LazyPlaylistView = React.lazy(() => import("./Playlist/View/PlaylistRouter"))
const LazySettings = React.lazy(() => import("./Settings/SettingsRouter"))
@ -123,10 +122,6 @@ class MusicTools extends Component {
<ListItemIcon><GroupWork /></ListItemIcon>
<ListItemText primary="Tags" />
</ListItem>
<ListItem button key="maths" component={Link} to='/app/maths/count'>
<ListItemIcon><PieChart /></ListItemIcon>
<ListItemText primary="Maths" />
</ListItem>
<ListItem button key="settings" component={Link} to='/app/settings/password'>
<ListItemIcon><Build /></ListItemIcon>
<ListItemText primary="Settings" />
@ -155,7 +150,6 @@ class MusicTools extends Component {
<Route path="/app/playlists" component={LazyPlaylists} />
<Route path="/app/tags" component={LazyTags} />
<Route path="/app/tag/:tag_id" component={LazyTag} />
<Route path="/app/maths" component={LazyMaths} />
<Route path="/app/settings" component={LazySettings} />
{ this.state.type == 'admin' && <Route path="/app/admin" component={LazyAdmin} /> }
<Route path='/app/playlist/:name' component={LazyPlaylistView} />

View File

@ -305,6 +305,7 @@ export class Edit extends Component{
render(){
var date = new Date();
console.log("hello from edit");
const table = (
<div style={{maxWidth: '1000px', margin: 'auto', marginTop: '20px'}}>