def garbageCollector(): # Jero here db = getDb() # Get available space total, used, free = shutil.disk_usage("/") # while space is less that 20% delete oldest unamed file while(free/total < 0.2): # using shutil to calculate disk usage total, used, free = shutil.disk_usage("/") # get oldest takes db, and oldest = getOldest(db) vidID = oldest.get('Id') pipeID = oldest.get('PipeID') # Create and execute multiple queries to free up space runQuery = deleteRunTask(db, vidID) deleteIt(db, runQuery) vidQuery = deleteVideoTask(db, vidID) deleteIt(db, vidQuery) tagQuery = deleteTagTask(db, vidID) deleteIt(db, tagQuery) return
def buildRun(target): """Builds a single run""" db = getDb() run = getVideo(db, target) tags = getTagIDs(db, run.get('Id')) vidTags = [] for tag in tags: vidTags.append(getTag(db, tag[0])) vidTags.sort(key=lambda tag: tag.get('Position')) run.update({'tag': vidTags}) if run.get("PipeID"): pipe = getPipe(db, run.get("PipeID")) run.update({'Lat': pipe.get('Lat')}) run.update({'Longi': pipe.get('Longi')}) else: run.update({'Lat': None}) run.update({'Longi': None}) run.update({'ShowRun': True}) run.update({'ShowTag': False}) return run
def editRun(): """edits a runs information""" db = getDb() userInput = request.json updateVideo(db, userInput["Id"], userInput["Name"], userInput["DriverName"], userInput["Tagged"], userInput["Direction"]) return jsonify({})
def deleteTag(): """Recieves a remove tag request""" data = request.json tagID = data.get("Id") db = getDb() deleteTagTask(db, tagID) db.close() return jsonify({})
def editPin(): """edits a runs tagged status""" db = getDb() userInput = request.json query = ("UPDATE Video SET " "Tagged = {} " "WHERE Id = {} ".format(userInput["tagged"], userInput["id"])) sendCommand(db, query) return jsonify({})
def getRuns(): """gets all Runs in the database""" db = getDb() videos = db.cursor(dictionary=True, buffered=True) videos.execute("SELECT * FROM Video ORDER BY Name ASC, DateTaken ASC") tagVids = [] namVids = [] noNamVids = [] for run in videos: tags = getTagIDs(db, run.get('Id')) vidTags = [] for tag in tags: vidTags.append(getTag(db, tag[0])) run.update({'tags': vidTags}) if run.get("PipeID"): pipe = getPipe(db, run.get("PipeID")) run.update({'Lat': pipe.get('Lat')}) run.update({'Longi': pipe.get('Longi')}) else: run.update({'Lat': None}) run.update({'Longi': None}) run.update({'ShowRun': True}) run.update({'ShowTag': False}) if (run.get('Tagged') and run.get('Tagged') > 0): tagVids.append(run) elif ((run.get('Tagged') is None or run.get('Tagged') == 0) and run.get('Name') is not None and run.get('Name') != ''): namVids.append(run) else: noNamVids.append(run) videos.close() db.close() allVideos = [tagVids, namVids, noNamVids] return jsonify(allVideos)
def run(): """Recieves a remove run request""" data = request.json print(data) targetID = data.get("Id") pipe = data.get("pipeID") date = data.get("date") db = getDb() deleteRunTask(db, targetID) db.close() removeRun(pipe, date) return jsonify({})
def newRun(): """Inserts a new run""" db = getDb() userInput = request.json name = userInput['Name'] driverName = userInput['DriverName'] tagged = userInput['Tagged'] pipeID = userInput['PipeID'] direction = userInput['Direction'] lat = userInput['Lat'] longi = userInput['Longi'] tags = userInput['tags'] error = None print(type(tags)) print(tags[0]) if not pipeID: error = 'PipeID is required.' elif not direction: error = 'Direction is required.' if error is None: checker = db.cursor(dictionary=True, buffered=True) query = ("SELECT * " "FROM Pipe " "WHERE Id = '{}'".format(pipeID)) checker.execute(query) if(not checker.fetchall()): query = ("INSERT INTO Pipe (Id, Lat, Longi)" "VALUES ('{}', {}, {})".format( pipeID, lat, longi)) sendCommand(db, query) checker.close() query = ("INSERT INTO Video (Name, PipeID, DriverName, DateTaken, Tagged, Direction) VALUES" "('{}', '{}', '{}', NOW(), {}, '{}')".format( name, pipeID, driverName, tagged, direction)) videoID = sendCommand(db, query) videoData = getVideo(db, videoID) for tag in tags: print(type(tag)) query = ("INSERT INTO TaggedLocs (Position, Lat, Longi, VideoTime)" "VALUES ({}, {}, {}, {})".format( tag["Position"], tag["Lat"], tag["Longi"], tag["VideoTime"])) print(query) tagID = sendCommand(db, query) query = ("INSERT INTO VideoToTags (VideoID, TagID)" "VALUES ({}, {})".format( videoID, tagID)) print(query) sendCommand(db, query) moveFiles(videoData.get('PipeID'), str( videoData.get('DateTaken')).replace(' ', '_')) # add tags now return jsonify({})