Ejemplo n.º 1
0
def loadTests(qie, tester, date, testData, path, overwrite):
    """ Loads in all test results """
    attempts = []

    for test in testData.keys():
        try:
            temp_test = Test.objects.get(abbreviation=test)
        except:
            sys.exit('Test "%s" not in database' % test)

        prev_attempts = list(
            Attempt.objects.filter(card=qie, test_type=temp_test))
        attempt_num = len(prev_attempts) + 1
        if not testData[test] == "na":
            if testData[test]:
                temp_attempt = Attempt(
                    card=qie,
                    plane_loc="default",
                    test_type=temp_test,
                    attempt_number=attempt_num,
                    tester=tester,
                    date_tested=date,
                    num_passed=1,
                    num_failed=0,
                    temperature=-999,
                    humidity=-999,
                    log_file=path,
                    hidden_log_file=path,
                )
            else:
                temp_attempt = Attempt(
                    card=qie,
                    plane_loc="default",
                    test_type=temp_test,
                    attempt_number=attempt_num,
                    tester=tester,
                    date_tested=date,
                    num_passed=0,
                    num_failed=1,
                    temperature=-999,
                    humidity=-999,
                    log_file=path,
                    hidden_log_file=path,
                )
            if overwrite:
                for prev_att in prev_attempts:
                    prev_att.revoked = True
                    prev_att.save()

            attempts.append(temp_attempt)
    return attempts
Ejemplo n.º 2
0
def getData(data, qiecard, tester_name, comments):
    """Main function to grab data from the JSON file"""
    attemptlist = []

    for test in data.keys():
        try:
            # Test is in the database
            temp_test = Test.objects.get(abbreviation=test)
        except:
            # Test is NOT in the database
            temp_test = Test(name=test, abbreviation=test)
            temp_test.save()
        
        prev_attempts = list(Attempt.objects.filter(card=qiecard, test_type=temp_test))
        attempt_num = len(prev_attempts) + 1
      #  if str(data[test]) == "true":
        temp_attempt = Attempt(card=qiecard,
                               date_tested=timezone.now(),
                               plane_loc="default",
                               attempt_number=attempt_num,
                               test_type=temp_test,
                               result=data[test][0],
                               times_passed=data[test][1],
                               times_failed=data[test][2],
                               # run=run_num,
                               tester=Tester.objects.get(username=tester_name),
                               comments=comments)

      #  else:
      #      temp_attempt = Attempt(card=qiecard,
      #                             date_tested=timezone.now(),
      #                             plane_loc="default",
      #                             attempt_number=attempt_num,
      #                             test_type=temp_test,
      #                             result=0,
      #                             # run=run_num,
      #                             tester=Tester.objects.get(username="******"),
      #                             comments=comments) 
        temp_attempt.save()
        attemptlist.append(temp_attempt)

        for pa in prev_attempts:
            pa.revoked=True
            pa.save()
    
            
    return attemptlist
try:
    temp_test = Test.objects.get(abbreviation=test)
except:
    sys.exit('Test "%s" not in database' % test)

prev_attempts = list(Attempt.objects.filter(card=qie, test_type=temp_test))
attempt_num = len(prev_attempts) + 1
card.save()
if cardData[test]:
    temp_attempt = Attempt(
        card=card,
        plane_loc="default",
        test_type=temp_test,
        attempt_number=attempt_num,
        tester=tester,
        date_tested=date,
        num_passed=1,
        num_failed=0,
        temperature=-999,
        humidity=-999,
        log_file=path,
        hidden_log_file=path,
    )
else:
    temp_attempt = Attempt(
        card=card,
        plane_loc="default",
        test_type=temp_test,
        attempt_number=attempt_num,
        tester=tester,
        date_tested=date,
        num_passed=0,
phaseName = os.path.join(os.path.dirname(fileName),
                         "phase_plot" + str(cardData["Jslot"]))
media = moveImageDir(qie, phaseName)

prev_attempts = list(Attempt.objects.filter(card=qie, test_type=temp_test))
attempt_num = len(prev_attempts) + 1
if (data[0] == 0 and data[1] == 0):
    temp_attempt = Attempt(
        card=qie,
        plane_loc=cardData["Jslot"],
        test_type=temp_test,
        attempt_number=attempt_num,
        tester=tester,
        date_tested=test_time,
        num_passed=0,
        num_failed=0,
        revoked=True,
        comments="This test returned no testing data",
        log_file=url,
        image=media,
        hidden_log_file=url,
    )
else:
    temp_attempt = Attempt(
        card=qie,
        plane_loc="default",
        test_type=temp_test,
        attempt_number=attempt_num,
        tester=tester,
        date_tested=test_time,
    test = Test.objects.get(name="Card Picture")
except ObjectDoesNotExist:
    test = Test(name="Card Picture", abbreviation="moneyshot")
    test.save()

tester = Tester.objects.get(username="******")

try:
    temp_attempt = Attempt.objects.get(card=qiecard,
                                       test_type__name="Card Picture")
except ObjectDoesNotExist:
    temp_attempt = Attempt(
        card=qiecard,
        result=1,
        date_tested=timezone.now(),
        plane_loc="default",
        attempt_number=1,
        tester=tester,
        test_type=Test.objects.get(name="Card Picture"),
    )

shutil.move(
    file_name,
    os.path.join(MEDIA_ROOT, "uploads", "qieCards", qiecard.barcode,
                 os.path.basename(file_name)))

temp_attempt.image = os.path.join("uploads", "qieCards", qiecard.barcode,
                                  os.path.basename(file_name))
temp_attempt.save()
set_card_status(qiecard)
print "Card Uploaded Succesfully"
Ejemplo n.º 6
0
def getData(data, rawUID, qiecard, run_num, tester_name):
    """Main function to grab data from the JSON file"""
    attemptlist = {}
    channels_passed = {}
    channels_failed = {}
    varlist = []
    first_channel = True
    

    for position in data[rawUID].keys():
        for channel in data[rawUID][position].keys():
            newchannel = Channel(number=CHANNEL_MAPPING[position][channel[-1]], card=qiecard)
            if newchannel not in list(qiecard.channel_set.all()):
                newchannel.save()
            failed_channel = {}
            for test in data[rawUID][position][channel].keys():
                failed_test = False
                try:
                    # Test is in the database
                    temp_test = Test.objects.get(abbreviation=test)
                    if test not in channels_passed.keys() and test not in channels_failed.keys():
                        channels_passed[test] = 0
                        channels_failed[test] = 0
                    if test not in failed_channel:
                        failed_channel[test] = False
                except ObjectDoesNotExist:
                    # Test is not in the database and can be created
                    temp_test = Test(name=test, abbreviation=test)
                    temp_test.save()
                    channels_passed[test] = 0
                    channels_failed[test] = 0
                    
                if first_channel:
                    # Only get/create attempts once per card
                    prev_attempts = list(Attempt.objects.filter(card=qiecard, test_type=temp_test))
                    attempt_num = len(prev_attempts) + 1
                    temp_attempt = Attempt(card=qiecard, 
                                           date_tested=timezone.now(), 
                                           plane_loc="default", 
                                           attempt_number=attempt_num, 
                                           test_type=temp_test,
                                           run=run_num,
                                           tester=Tester.objects.get(username=tester_name),
                                           comments=data["Comments"])
                    temp_attempt.save()
                    attemptlist[test] = temp_attempt
                        
                    for pa in prev_attempts:
                        pa.revoked=True
                        pa.save()
                            
                            
                else:
                    # Get the correct attempt
                    temp_attempt = attemptlist[test]
                        
                for variable in data[rawUID][position][channel][test].keys():
                    temp_value = data[rawUID][position][channel][test][variable][0]
                    temp_result = data[rawUID][position][channel][test][variable][1]
                                
                    temp_var = Variable(name=variable, value=temp_value, attempt=attemptlist[test], test_pass=temp_result)
                    varlist.append(temp_var)
                    if temp_result == 0.0:
                        # If the test failed, set a flag that the channel failed 
                        failed_test = True
                                    
                                    
                if failed_test:
                    failed_channel[test] = True
                    channels_failed[test] += 1
                else:
                    failed_channel[test] = False
                    channels_passed[test] += 1
                                
                                
            if first_channel:
                first_channel = False
    
    for var in varlist:
        var.save()
    
    return attemptlist, channels_passed, channels_failed