Example #1
0
def printResults(string, answers={}):
                history = DBtransactions.parseInput(string)
                if not isinstance(history, basestring):
                        historyString = views.historyToString(history)
			historyTable = views.historyToTable(history)
                        result = DBtransactions.computeEverything(history)
			conflictOperations = views.conflictOperationsToString(result['conflictOperations'])
			readingTAs = views.readingTAsToString(result['readingTAs'])
			committedTransactions = views.transactionListToString(result['committedTAs'])
			abortedTransactions = views.transactionListToString(result['abortedTAs'])
                        graph = result['graph']
                        isSR = result['SR']
                        operationsNotRC = result['operationsNotRC']
			isRC = result['RC']
                        operationsNotACA = result['operationsNotACA']
			isACA = result['ACA']
                        operationsNotST = result['operationsNotST']
			isST = result['ST']
			
			resultString =  historyTable+views.wrapInPanel("Konfliktoperationen", conflictOperations,3)+views.wrapInPanel("Lesende Transaktionen", readingTAs, 3)+views.wrapInPanel("Committete Transaktionen", committedTransactions, 3)+views.wrapInPanel("Abortete Transaktionen", abortedTransactions, 3)+views.htmlGraph()+"<div>"+views.wrapInPanel("Eigenschaften von H := "+historyString, views.booleanPropertyToString("serialisierbar", isSR)+views.propertyToString("rücksetzbar", history, operationsNotRC)+views.propertyToString("vermeidet kaskadierendes Rücksetzen", history, operationsNotACA)+views.propertyToString("strikt", history, operationsNotST), 12)+"</div>"+printjquery(graph, history)
                	if answers:
				if answers['SR'] == isSR and  answers['RC'] == isRC and  answers['ACA'] == isACA and  answers['ST'] == isST:
					returnString = printCheckboxes(answers) + views.getMessageBox("Richtig!","thumbs-up") + resultString
				else:
					returnString = printCheckboxes(answers) + views.getMessageBox("Leider falsch!","thumbs-down")
			else:
				returnString = printCheckboxes(result) + resultString
		else:
			returnString = printCheckboxes(answers) + history
		return returnString
Example #2
0
def printResults(string, answers={}):
                history = DBtransactions.parseInput(string)
                if not isinstance(history, basestring):
                        historyString = views.historyToString(history)
			historyTable = views.historyToTable(history)
                        result = DBtransactions.computeEverything(history)
			conflictOperations = views.conflictOperationsToString(result['conflictOperations'])
			readingTAs = views.readingTAsToString(result['readingTAs'])
			committedTransactions = views.transactionListToString(result['committedTAs'])
			abortedTransactions = views.transactionListToString(result['abortedTAs'])
                        graph = result['graph']
                        isSR = result['SR']
                        operationsNotRC = result['operationsNotRC']
			isRC = result['RC']
                        operationsNotACA = result['operationsNotACA']
			isACA = result['ACA']
                        operationsNotST = result['operationsNotST']
			isST = result['ST']
			
			resultString =  historyTable+views.wrapInPanel("Konfliktoperationen", conflictOperations,3)+views.wrapInPanel("Lesende Transaktionen", readingTAs, 3)+views.wrapInPanel("Committete Transaktionen", committedTransactions, 3)+views.wrapInPanel("Abortete Transaktionen", abortedTransactions, 3)+views.htmlGraph()+"<div>"+views.wrapInPanel("Eigenschaften von H := "+historyString, views.booleanPropertyToString("serialisierbar", isSR)+views.propertyToString("rücksetzbar", history, operationsNotRC)+views.propertyToString("vermeidet kaskadierendes Rücksetzen", history, operationsNotACA)+views.propertyToString("strikt", history, operationsNotST), 12)+"</div>"+printjquery(graph, history)
                	if answers:
				if answers['SR'] == isSR and  answers['RC'] == isRC and  answers['ACA'] == isACA and  answers['ST'] == isST:
					returnString = printCheckboxes(answers) + views.getMessageBox("Richtig!","thumbs-up") + resultString
				else:
					returnString = printCheckboxes(answers) + views.getMessageBox("Leider falsch!","thumbs-down")
			else:
				returnString = printCheckboxes(result) + resultString
		else:
			returnString = printCheckboxes(answers) + history
		return returnString
Example #3
0
def decompositionAlgorithm(targetNf, fds, relation, mvds=[]):
    fds = fds[:]

    if targetNf == "BCNF":
        to4NF = False
    else:
        to4NF = True

    additionalFds = getAdditionalFDs(fds)
    fds.extend(additionalFds)

    additionalMvds = []
    if (to4NF):
        additionalMvds = getAdditionalMVDs(mvds + fds, relation)
        mvds.extend(additionalMvds)

    heading = "Schema in " + targetNf
    keysOfRelation = getKeys(relation, fdsInRelation(fds, relation))

    #relation, key of relation, relation name
    relations = [(relation, "", keysOfRelation, fds, mvds)]

    stepsStrings = []

    targetNfReached = False

    while not targetNfReached:
        additionalFdsInR = []
        additionalMvdsInR = []
        if not to4NF:
            #BCNF
            i, r = getFirstNonBCNFRelation([x[0] for x in relations], fds)
            if i == -1:
                targetNfReached = True
            else:
                fdsInR = fdsInRelation(fds, r)
                if len(relations) == 1:
                    #show alert for additional FDs only in the first step
                    additionalFdsInR = fdsInRelation(additionalFds, r)
                mvdsInR = []

                currentfd = getFirstNonBCNFfd(r, fdsInR)
                currentfdString = views.fdToHtmlString(currentfd)
        else:
            #4NF
            i, r = getFirstNon4NFRelation([x[0] for x in relations], fds, mvds)
            if i == -1:
                targetNfReached = True
            else:
                fdsInR = fdsInRelation(fds, r)
                if len(relations) == 1:
                    #show alert for additional FDs only in the first step
                    additionalFdsInR = fdsInRelation(additionalFds, r)
                    additionalMvdsInR = mvdsInRelation(additionalMvds, r)
                mvdsInR = mvdsInRelation(mvds, r)
                currentfd = getFirstNonBCNFfd(r, fdsInR)
                if currentfd is ():
                    currentfd = getFirstNon4NFmvd(r, fdsInR, mvdsInR)
                currentfdString = views.mvdToHtmlString(currentfd)

        if not targetNfReached:
            r1, r2 = splitRelationAtFdMvd(r, currentfd)

            fdsInR1 = fdsInRelation(fds, r1)
            fdsInR2 = fdsInRelation(fds, r2)

            mvdsInR1 = mvdsInRelation(mvds, r1)
            mvdsInR2 = mvdsInRelation(mvds, r2)

            keysOfR1 = getKeys(r1, fdsInR1)
            keysOfR2 = getKeys(r2, fdsInR2)

            relations.append(
                (r1, relations[i][1] + "1", keysOfR1, fdsInR1, mvdsInR1))
            relations.append(
                (r2, relations[i][1] + "2", keysOfR2, fdsInR2, mvdsInR2))

            relationString = views.relationToString(relations[i][0],
                                                    relations[i][1],
                                                    getKeys(r, fdsInR), fdsInR,
                                                    mvdsInR, additionalFdsInR,
                                                    additionalMvdsInR)

            stepsStrings.append(
                views.wrapInPanel(
                    relationString + "  nicht in " +
                    targetNf, currentfdString + " verletzt die " + targetNf +
                    ".<br/>" + relationString +
                    """  zerlegen in<br/><ul style="list-style-type:square;"><li>"""
                    +
                    views.relationToString(r1, relations[i][1] +
                                           "1", keysOfR1, fdsInR1, mvdsInR1) +
                    "</li><li>" +
                    views.relationToString(r2, relations[i][1] + "2", keysOfR2,
                                           fdsInR2, mvdsInR2), 2) +
                """</li></ul>""")

            del relations[i]

    resultString = ""
    if len(relations) > 1:
        #at least one relation has been split, thus additional fds/mvds have been displayed in this step (if there are any). We do not mark them again when displaying the result.
        additionalFds = []
        additionalMvds = []
    for r in relations:
        resultString = resultString + views.relationToString(
            r[0], r[1], r[2], r[3], r[4], additionalFds,
            additionalMvds) + "<br/>"

    if len(stepsStrings) % 2 == 0:
        numberOfColumns = 1
    else:
        numberOfColumns = 2
    resultString = views.wrapInPanel(heading,
                                     "<strong>" + resultString + "</strong>",
                                     numberOfColumns)
    stepsString = ""
    for r in stepsStrings:
        stepsString = stepsString + r
    return (relations, stepsString, resultString)
Example #4
0
def decompositionAlgorithm(targetNf, fds, relation, mvds=[]):
	fds = fds[:]

	additionalFds = getAdditionalFDs(fds)
	fds.extend(additionalFds)

	if targetNf == "BCNF":
		to4NF=False
	else:
		to4NF=True

	heading = "Schema in "+targetNf
	keysOfRelation = getKeys(relation,fdsInRelation(fds, relation))

	#relation, key of relation, relation name
	relations = [(relation, "", keysOfRelation, fds, mvds)]

	stepsStrings = []
	
	targetNfReached = False

	while not targetNfReached:
		additionalFdsInR = []
		if not to4NF:
			#BCNF
			i,r=getFirstNonBCNFRelation([x[0] for x in relations], fds)
			if i==-1:
				targetNfReached=True
			else:
				fdsInR = fdsInRelation(fds, r)
				if len(relations) == 1:
					#show alert for additional FDs only in the first step
					additionalFdsInR = fdsInRelation(additionalFds, r)
				mvdsInR = []
				currentfd = getFirstNonBCNFfd(r, fdsInR)
				currentfdString = views.fdToHtmlString(currentfd)
		else:
			#4NF
			i,r=getFirstNon4NFRelation([x[0] for x in relations], fds, mvds)
			if i==-1:
				targetNfReached=True
			else:
				fdsInR = fdsInRelation(fds, r)
				if len(relations) == 1:
					#show alert for additional FDs only in the first step
					additionalFdsInR = fdsInRelation(additionalFds, r)
				mvdsInR = mvdsInRelation(mvds, r)
				currentfd = getFirstNonBCNFfd(r, fdsInR)
				if currentfd is ():
					currentfd = getFirstNon4NFmvd(r, fdsInR, mvdsInR)
				currentfdString = views.mvdToHtmlString(currentfd)

		if not targetNfReached:
			r1, r2 = splitRelationAtFdMvd(r, currentfd)

			fdsInR1 = fdsInRelation(fds, r1)
			fdsInR2 = fdsInRelation(fds, r2)

			mvdsInR1 = mvdsInRelation(mvds, r1)
			mvdsInR2 = mvdsInRelation(mvds, r2)

			keysOfR1 = getKeys(r1,fdsInR1)
			keysOfR2 = getKeys(r2,fdsInR2)

			relations.append((r1, relations[i][1]+"1", keysOfR1, fdsInR1, mvdsInR1))
			relations.append((r2, relations[i][1]+"2", keysOfR2, fdsInR2, mvdsInR2))
			
			
			relationString = views.relationToString(relations[i][0], relations[i][1], getKeys(r, fdsInR), fdsInR, mvdsInR, additionalFdsInR)


			stepsStrings.append(views.wrapInPanel(relationString+"  nicht in "+targetNf, currentfdString+" verletzt die "+targetNf+".<br/>"+relationString+"""  zerlegen in<br/><ul style="list-style-type:square;"><li>"""+views.relationToString(r1, relations[i][1]+"1", keysOfR1, fdsInR1, mvdsInR1)+"</li><li>"+views.relationToString(r2, relations[i][1]+"2", keysOfR2, fdsInR2, mvdsInR2), 2)+"""</li></ul>""")

			del relations[i]
			
	resultString = ""
	if len(relations) > 1:
		#at least one relation has been split, thus additional fds have been displayed in this step (if there are any). We do not mark them again when displaying the result.
		additionalFds = []
	for r in relations:
		resultString = resultString + views.relationToString(r[0], r[1], r[2], r[3], r[4], additionalFds)+"<br/>"
	
	if len(stepsStrings) % 2 == 0:
		numberOfColumns = 1
	else:
		numberOfColumns = 2
	resultString =  views.wrapInPanel(heading, "<strong>"+resultString+"</strong>", numberOfColumns)  
	stepsString = ""
	for r in stepsStrings:
		stepsString = stepsString + r  
	return (relations, stepsString, resultString)