94 lines
2.3 KiB
Python
Executable File
94 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import matplotlib
|
|
matplotlib.use("Agg")
|
|
import seaborn as sns
|
|
sns.set(style="ticks")
|
|
import matplotlib.pyplot as plt
|
|
import pandas as pd
|
|
import os
|
|
from flask import Flask, url_for, render_template, jsonify, request, make_response, g
|
|
from flask_socketio import emit
|
|
import pdb
|
|
import csv
|
|
import io
|
|
import re
|
|
import base64
|
|
import shutil
|
|
|
|
import webview
|
|
import webbrowser
|
|
import app
|
|
import time
|
|
from threading import Thread, Event
|
|
import numpy as np
|
|
import random
|
|
from pysndfile import sndio
|
|
from scipy.optimize import minimize
|
|
|
|
from app import generate_matrix_stimulus
|
|
from matrix_test.helper_modules.filesystem import globDir, organiseWavs, prepareOutDir
|
|
from matrix_test_thread import MatTestThread
|
|
from pathops import dir_must_exist
|
|
from gen_participants import Participant
|
|
|
|
from config import server, socketio, participants
|
|
from route import *
|
|
from socket_handlers import *
|
|
|
|
class StimGenThread(Thread):
|
|
'''
|
|
Thread object for asynchronous processing of data in Python without locking
|
|
up the GUI
|
|
'''
|
|
def __init__(self, *args, **kwargs):
|
|
super(StimGenThread, self).__init__()
|
|
self.args = args
|
|
self.kwargs = kwargs
|
|
|
|
|
|
def process_stimulus(self):
|
|
'''
|
|
An example process
|
|
'''
|
|
filenames = generate_matrix_stimulus(*self.args, **self.kwargs)
|
|
generateSpeechShapedNoise(args['OutDir'], noiseDir, order=20, plot=True)
|
|
#socketio.emit('update-progress', {'data': '{}%'.format(percent)}, namespace='/main')
|
|
|
|
|
|
def run(self):
|
|
'''
|
|
This function is called when the thread starts
|
|
'''
|
|
self.process_stimulus()
|
|
socketio.emit('processing-complete', {'data': ''}, namespace='/main')
|
|
|
|
|
|
|
|
@server.after_request
|
|
def add_header(response):
|
|
# Disable caching? unsure why...
|
|
response.headers['Cache-Control'] = 'no-store'
|
|
return response
|
|
|
|
|
|
def set_trace():
|
|
import logging
|
|
log = logging.getLogger('werkzeug')
|
|
log.setLevel(logging.ERROR)
|
|
log = logging.getLogger('engineio')
|
|
log.setLevel(logging.ERROR)
|
|
pdb.set_trace()
|
|
|
|
|
|
def run_server():
|
|
'''
|
|
Start the Flask server
|
|
'''
|
|
# SocketIO objects are defined in config.py
|
|
socketio.run(server, host="127.0.0.1", port=23948, debug=True, use_reloader=False)
|
|
|
|
if __name__ == "__main__":
|
|
run_server()
|
|
|