Commit 13adf8b6 authored by Odair M.'s avatar Odair M.

Closes adega:#214: implement command analyze_all

parent b1b667b8
from django.core.management.base import BaseCommand
from submission.models import Submission
from degree.models import Degree
from submission.analysis.main import analyze
class Command(BaseCommand):
help = ' Reexecute last analyze of all degree'
def handle(self, *args, **options):
degrees = Degree.objects.all()
submissions = Submission.objects.all()
to_analyze = []
# for each degree, get last submission with sucessful and re execute
for degree in degrees:
# get all submissions of degree
submissions = Submission.objects.filter(degree=degree, analysis_status=Submission.STATUS_FINISHED)
# check if degree has submissions
if len(submissions) > 0:
# Put each submission on queue and set it to executing status
for submission in submissions.order_by('timestamp'):
submission.set_executing()
to_analyze.append(submission)
# Execute each analyze in chronological order
for submission in to_analyze:
analyze(submission)
from django.core.management.base import BaseCommand
from submission.models import Submission
from degree.models import Degree
from submission.analysis.main import analyze
class Command(BaseCommand):
help = ' Reexecute last analyze of all degree'
def handle(self, *args, **options):
degrees = Degree.objects.all()
submissions = Submission.objects.all()
to_analyze = []
# for each degree, get last submission with sucessful and re execute
for degree in degrees:
# get all submissions of degree
submissions = Submission.objects.filter(degree=degree, analysis_status=Submission.STATUS_FINISHED)
# check if degree has submissions
if len(submissions) > 0:
# sort reverse submission by timestamp and the most recent submission
submission = submissions.order_by('timestamp').reverse()[0]
submission.set_executing()
to_analyze.append(submission)
# Execute each analyze in chronological order
for submission in to_analyze:
analyze(submission)
\ No newline at end of file
...@@ -9,6 +9,7 @@ import traceback ...@@ -9,6 +9,7 @@ import traceback
def analyze(submission, debug=True): def analyze(submission, debug=True):
start_time = time.clock() start_time = time.clock()
start_time_exec = time.time() start_time_exec = time.time()
submission.set_executing()
try: try:
path = submission.path() path = submission.path()
dataframe = load_dataframes(path) dataframe = load_dataframes(path)
......
...@@ -37,7 +37,7 @@ class Submission(models.Model): ...@@ -37,7 +37,7 @@ class Submission(models.Model):
historico = models.FileField(upload_to=get_path) historico = models.FileField(upload_to=get_path)
matricula = models.FileField(upload_to=get_path) matricula = models.FileField(upload_to=get_path)
degree = models.ForeignKey(Degree) degree = models.ForeignKey(Degree, related_name='submissions')
timestamp = models.DateTimeField(default=timezone.now) timestamp = models.DateTimeField(default=timezone.now)
last = models.BooleanField(default=True) last = models.BooleanField(default=True)
processed = models.BooleanField(default=False) processed = models.BooleanField(default=False)
...@@ -89,6 +89,13 @@ class Submission(models.Model): ...@@ -89,6 +89,13 @@ class Submission(models.Model):
self.degree.name, self.degree.name,
self.timestamp) self.timestamp)
def set_executing(self):
self.processed = False
self.process_time = None
self.done_in = timezone.now()
self.analysis_status = 0
self.save()
def set_done(self, time): def set_done(self, time):
self.processed = True self.processed = True
self.process_time = time self.process_time = time
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment