From a178107abd6fd4a787ecb19faf280b32f36a5d62 Mon Sep 17 00:00:00 2001 From: Newnius Date: Thu, 9 Jul 2020 22:50:39 +0800 Subject: [PATCH] make sure tmp testfile is removed --- .idea/workspace.xml | 46 +++++++++++++++++++++++---------------------- serve.py | 14 ++++++++------ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9c81798..1f76ebc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,7 @@ + @@ -53,7 +54,7 @@ - + @@ -63,7 +64,7 @@ - + @@ -73,8 +74,8 @@ - - + + @@ -85,8 +86,8 @@ - - + + @@ -94,8 +95,8 @@ - - + + @@ -138,6 +139,7 @@ range exist trace + utf @@ -204,7 +206,7 @@ - + @@ -249,12 +251,12 @@ - + - @@ -416,17 +418,10 @@ - - - - - - - - - + + @@ -434,10 +429,17 @@ + + + + + + + - - + + diff --git a/serve.py b/serve.py index 0367fa7..b2e55e4 100644 --- a/serve.py +++ b/serve.py @@ -78,24 +78,24 @@ def predict(job, features): for feature in models[job]['features']: values.append(features[feature]) - datafile = './data/' + job + '.' + str(random.randint(1000, 9999)) + '.csv' + testfile = './data/' + job + '.' + str(random.randint(1000, 9999)) + '.csv' t = ['job'] t.extend(models[job]['features']) - with open(datafile, 'w', newline='') as csvfile: + with open(testfile, 'w', newline='') as csvfile: spamwriter = csv.writer( csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL ) spamwriter.writerow(t) - with open(datafile, 'a+', newline='') as csvfile: + with open(testfile, 'a+', newline='') as csvfile: spamwriter = csv.writer( csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL ) spamwriter.writerow(values) - testdata = pd.read_csv(datafile) + testdata = pd.read_csv(testfile) test_feature = testdata.iloc[:, 1:] predictions = {} @@ -103,13 +103,15 @@ def predict(job, features): # load the model from disk modelfile = './data/' + job + '_' + label + '.sav' if not os.path.exists(modelfile): + if os.path.exists(testfile): + os.remove(testfile) return -1, False model = pickle.load(open(modelfile, 'rb')) preds = model.predict(test_feature) predictions[label] = preds[0] - if os.path.exists(datafile): - os.remove(datafile) + if os.path.exists(testfile): + os.remove(testfile) return predictions, True