Exemple #1
0
 def DumpDataset(unicodedatasetindex = None):
     if unicodedatasetindex != None:
         # try:
         datasetindex = int(unicodedatasetindex)
         filepath = 'dataset/' + random_file_name(None, 'txt')
         # DB
         oldsinfo = OnlineDataset.objects.get(id = datasetindex)
         dsinfo = Dataset()
         dsinfo.name = oldsinfo.name
         dsinfo.path = filepath
         dsinfo.filetype = 'TXT'
         dsinfo.head = oldsinfo.head
         dsinfo.hashead = oldsinfo.hashead
         dsinfo.attr_delim = ',' 
         dsinfo.record_delim = '\n' 
         dsinfo.save()
         #file
         output = open(settings.MEDIA_ROOT + filepath, 'w')
         oldataset = OnlineDataset.ViewDataset(datasetindex)
         if oldataset == None:
             return 'false'
         output.write(','.join(map(str, oldataset.head)) + '\n')
         for line in oldataset.items:
             output.write(','.join(map(str, line)) + '\n')
         output.close()
         return 'true'
         # except:
         #     return 'false'
     return 'false'
Exemple #2
0
    def CreateTrain(unicodemodelindex = None):
        '''
            mdinfo: MLModel
            traintask: TrainingTask
            mdruntask: ModelRunTask
        '''
        if unicodemodelindex != None:
            modelindex = int(unicodemodelindex)
            mdinfo = MLModel.objects.get(id = modelindex)
            if mdinfo != None:
                # New Task in DB model
                traintask = TrainingTask()
                traintask.name = ''
                traintask.modelprototype = mdinfo.modeltype
                traintask.modelindex = modelindex
                traintask.save()
                # Modify Model Record
                mdinfo.modelstatus = 'TRAINING'
                mdinfo.save()
                # Open dataset on db
                if mdinfo.datasetprototype == 'LOCAL':
                    dsinfo = Dataset.GetDataset(mdinfo.datasetindex) 
                else:
                    dsinfo = OnlineDataset.GetDataset(mdinfo.datasetindex)
                # Create Machine Learning Instance
                # Get TrainingTask id
                mdruntask = ModelRunTask(TrainingTask.objects.all()[len(TrainingTask.objects.all())-1].id, mdinfo, dsinfo)
                mdruntask.Start()

                # now Training is over
                mdinfo.modelstatus = 'TRAINED'
                # save training result
                mdinfo.model_path = 'cache/models/'+random_file_name(None,'trd')
                mdruntask.Save(mdinfo.model_path)
                mdinfo.save()
                traintask.delete()
                
                return 'true'
            return 'false'
Exemple #3
0
def get_model_upload_to(instance, filename):
    return settings.MEDIA_ROOT + 'upload/models/' + random_file_name(filename)
Exemple #4
0
def get_upload_to(instance, filename):
    # paths = { 'I':'images/', 'V':'videos/', 'A':'audio/', 'D':'documents'/ }
    # return settings.MEDIA_ROOT + 'content/' + paths[instance.content_type] + filename
    return 'dataset/' + random_file_name(filename)