コード例 #1
0
    def run(self, hw, part):
        self.projectName = 'Instrumentation'
        self.testClient = CodewebsUnitTestClient(UNITTESTERHOST)

        astdir = os.path.join(FileSystem.getAstDir(),
                              'ast_' + str(hw) + '_' + str(part))
        outputDir = os.path.join(FileSystem.getDataDir(),\
                'Instrumentation',str(hw) + '_' + str(part))

        srcFiles = [
            fname for fname in os.listdir(astdir) if fname[-5:] == '.code'
        ]
        for idx, fname in enumerate(srcFiles):
            if idx % 100 == 0:
                print(str(idx) + ' of ' + str(len(srcFiles)))

            astId = fname[4:-5]
            outputPath = os.path.join(outputDir, 'ast_' + astId + '.trace')
            fullname = os.path.join(astdir, fname)
            try:
                instrumentedCodePath = self.instrument(fullname, outputPath)
            except:
                print('Instrumentation Error')
                continue

            with open(instrumentedCodePath) as fid:
                code = fid.read()
                self.testClient.call(code)
                testResult = self.testClient.wait()
コード例 #2
0
    def run(self):
        dirName = os.path.join(FileSystem.getDataDir(), 'incorrects')
        if not os.path.exists(dirName):
            os.makedirs(dirName)
        logDirName = os.path.join(FileSystem.getLogDir(), 'incorrects')
        if not os.path.exists(logDirName):
            os.makedirs(logDirName)

        logFileName = os.path.join(logDirName, 'log')
        logging.basicConfig(filename = logFileName, \
                        format = '%(asctime)s %(message)s', \
                        datefmt = '%m/%d/%Y %I:%M:%S %p', level = logging.INFO)
        logging.info('ListIncorrects()')

        for part in MLClass.allProblems():
            print(part)
            logging.info('Problem ' + str(part))
            incorrectASTs, incorrectSubmissions = \
                                self.getASTids(part, 'incorrects')
            correctASTs, correctSubmissions = self.getASTids(part, 'corrects')

            self.writeASTs(incorrectASTs, 'incorrects', part, dirName)
            self.writeASTs(correctASTs, 'corrects', part, dirName)

            self.writeNumSubmissions(incorrectSubmissions, \
                                        'incorrects', part, dirName)
            self.writeNumSubmissions(correctSubmissions, \
                                        'corrects', part, dirName)

            submissionMap = self.getSubmissionMap(part)
            self.writeUsers(incorrectSubmissions, 'incorrects', \
                                        part, submissionMap, dirName)
            self.writeUsers(correctSubmissions, 'corrects', \
                                        part, submissionMap, dirName)
コード例 #3
0
 def getOutputFilePath(self, assn, threshold, label):
     dataDir = FileSystem.getDataDir()
     outputDir = os.path.join(dataDir, 'incorrects')
     if not os.path.exists(outputDir):
         os.makedirs(outputDir)
     fileName = label + 'Graph.' + str(assn) + '.sparse' + str(
         threshold) + '.gml'
     return os.path.join(outputDir, fileName)
コード例 #4
0
 def readTemplate(self):
     path = os.path.join(FileSystem.getDataDir(), 'equivalence',
                         'templates', 'template.html')
     with open(path) as fid:
         template = fid.read()
     (before, after) = template.split('{{hierarchy}}')
     (middle, after) = after.split('{{script}}')
     self.template = {'before': before, 'middle': middle, 'after': after}
コード例 #5
0
 def getAsts(self, assn, label):
     dataDir = FileSystem.getDataDir()
     outputDir = os.path.join(dataDir, 'incorrects')
     fileName = label + '_' + str(assn) + '.txt'
     path = os.path.join(outputDir, fileName)
     astList = []
     astFile = open(path)
     for line in astFile.readlines():
         astList.append(int(line))
     return Set(astList)
コード例 #6
0
    def run(self):
        dirname = 'DumpNumSubmissions'
        FileSystem.initializeLogging(dirname)

        outputDir = os.path.join(FileSystem.getDataDir(), dirname)
        if not os.path.exists(outputDir):
            os.makedirs(outputDir)

        for (h, p) in MLClass.allProblems():
            assn = Assignment(h, p)
            path = os.path.join(outputDir,\
                    'NumSubmissions_' + str(assn) + '.txt')
            #self.loadOutputs(assn, astOutputPath, mapOutputPath)
            self.loadNumSubmissions(assn, path)
コード例 #7
0
 def __init__(self, hwId, partId):
     self.hwId = hwId
     self.partId = partId
     self.dataDir = os.path.join(
         FileSystem.getDataDir(),
         'octave_unittest/mlclass-ex' + str(self.hwId))
     #print(self.dataDir)
     assert (os.path.exists(self.dataDir))
     self._loadCorrect()
     self.workingDir = os.path.join(
         FileSystem.getWorkingDir(),
         'unitTesting_' + str(self.hwId) + '_' + str(self.partId))
     self.createWorkingDir()
     self.refreshWorkingDir()
     self._writeUnitTestScript()
     self._writeUnitTestFilesScript()
     #print(self.fileScriptName)
     self.unitTestFile = self.workingDir + '/' + self.getUnitTestFile()
コード例 #8
0
    def run(self):
        self.initializeLog()
        for (h, p) in self.getAllParts():
            assn = Assignment(h, p)
            logging.info('PrecomputeNN (hw,part): ' + str(assn))
            corrects = self.getASTs(assn, 'corrects')
            incorrects = self.getASTs(assn, 'incorrects')
            distanceMatrix = FileSystem.loadDistanceMatrix(
                assn.getTuple(), False)
            subIdMap = FileSystem.loadSubmissionIdMap(assn.getTuple())
            astNetwork = AstNetwork(assn.getTuple(), distanceMatrix, subIdMap)
            NNmap = self.getNN(corrects, incorrects, astNetwork)

            outputDir = os.path.join(FileSystem.getDataDir(),
                                     'nearestNeighbors')
            if not os.path.exists(outputDir):
                os.makedirs(outputDir)
            outputPath = os.path.join(outputDir, 'NNmap_' + str(assn) + '.txt')
            self.writeNN(outputPath, NNmap)
コード例 #9
0
 def __init__(self, assn):
     self.equivDir = os.path.join(FileSystem.getDataDir(), \
                 'equivalence','equivalence_' + str(assn))
     self.levels = []
     for d in os.listdir(self.equivDir):
         try:
             self.levels.append(int(d))
         except ValueError:
             pass
     self.classes = {}
     self.levelMap = {}
     for level in self.levels:
         for d in os.listdir(os.path.join(self.equivDir, str(level))):
             prefix = d.split('.')[0]
             self.levelMap[int(prefix)] = level
             try:
                 self.classes[level].append(int(prefix))
             except KeyError:
                 self.classes[level] = [int(prefix)]
             except ValueError:
                 pass
コード例 #10
0
 def getGraphPath(self, assn, threshold, label):
     dataDir = FileSystem.getDataDir()
     incorrectsDir = os.path.join(dataDir, 'incorrects')
     filename = label + 'Graph.' + str(assn) + '.sparse' + str(
         threshold) + '.gml'
     return os.path.join(incorrectsDir, filename)
コード例 #11
0
#! /usr/bin/env python

import os
import sys
sys.path.append(os.path.abspath('../../'))
from src.util.RunExternal import RunExternal
from src.util.FileSystem import FileSystem
import MySQLdb as mdb
import json
import logging

ASTCMD = os.path.join(FileSystem.getBinDir(), 'astgen')
TARCMD = 'tar -czf'
tmpdir = os.path.join(FileSystem.getWorkingDir(), 'octtojson')
logdir = os.path.join(FileSystem.getLogDir(), 'octtojson')
datadir = os.path.join(FileSystem.getDataDir(), 'ast')

astfilePrefix = 'ast'
octaveSuffix = '.m'
JSONSuffix = '.json'
codeSuffix = '.code'
mapSuffix = '.map'
tarSuffix = '.tar.gz'

MAXTIME = 10  # in seconds

# Needs to be configured to run properly
REMOTEDB = False
if REMOTEDB:
    dbServer = 'galois.stanford.edu'
    dbUser = '******'
コード例 #12
0
 def getOutputDir(self):
     path = os.path.join(FileSystem.getDataDir(), 'equivalence',
                         'html_' + str(assn))
     if not os.path.exists(path):
         os.makedirs(path)
     return path