From 841d47e9c1a1164a660b87f4dae8dedc2ff9cfb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Conrad=20Gro=C3=9Fer?= Date: Thu, 4 Jul 2019 18:39:01 +0200 Subject: [PATCH] Misc Cleanup Update --- src/algorithms/dmtest.py | 4 +- src/algorithms/{ => k-means}/kmeansMkI.py | 0 src/algorithms/{ => k-means}/kmeansMkI_2d.py | 0 src/data_generators/randomi.py | 101 ++++++++++--------- src/main.py | 39 ++++--- src/modules/importer.py | 2 +- src/template.py | 36 +++---- 7 files changed, 95 insertions(+), 87 deletions(-) rename src/algorithms/{ => k-means}/kmeansMkI.py (100%) rename src/algorithms/{ => k-means}/kmeansMkI_2d.py (100%) diff --git a/src/algorithms/dmtest.py b/src/algorithms/dmtest.py index 1f6b4c8..fc51060 100644 --- a/src/algorithms/dmtest.py +++ b/src/algorithms/dmtest.py @@ -28,7 +28,7 @@ def generateNumber(numberLenght, startingNumber): return number -# Function for writing data into a file +# Function for writing data into a file # content = string, nameChunkStart and namePartStart are for better naming # /testdata/ folder has to be created at this point def writeFile(content, nameChunkStart, namePartStart): @@ -56,7 +56,7 @@ def numGen(entries, cluster, int_lenght, suffle_value): generateNumber( int_lenght - 1, clusterArray[cluster_decider] - )) + )) if suffle_value: shuffle(dataArray) diff --git a/src/algorithms/kmeansMkI.py b/src/algorithms/k-means/kmeansMkI.py similarity index 100% rename from src/algorithms/kmeansMkI.py rename to src/algorithms/k-means/kmeansMkI.py diff --git a/src/algorithms/kmeansMkI_2d.py b/src/algorithms/k-means/kmeansMkI_2d.py similarity index 100% rename from src/algorithms/kmeansMkI_2d.py rename to src/algorithms/k-means/kmeansMkI_2d.py diff --git a/src/data_generators/randomi.py b/src/data_generators/randomi.py index b6d0981..6b486b7 100644 --- a/src/data_generators/randomi.py +++ b/src/data_generators/randomi.py @@ -11,68 +11,77 @@ from datetime import date import multiprocessing # randomI function which creates each file + + def randomI(units, rows, rowLength, partstart): - for setcounter in range(0, units): - writeFile(generateFile(rows, rowLength), setcounter, partstart) + for setcounter in range(0, units): + writeFile(generateFile(rows, rowLength), setcounter, partstart) # Function for generating the content of one single file + + def generateFile(rows, rowLength): - content = [] - for y in range(0, rows): - content.append(generateRow(rowLength)) - return content + content = [] + for y in range(0, rows): + content.append(generateRow(rowLength)) + return content # Function for generating the content of one single row randomly + + def generateRow(rowLength): - row = "" - for z in range(0, rowLength): - row = row + str(randint(0, 9)) - return row + row = "" + for z in range(0, rowLength): + row = row + str(randint(0, 9)) + return row # Function for writing data into a file + + def writeFile(content, setcounter, partstart): - filenumber = int(setcounter) + int(partstart) - file = open("testdata/file" + str(filenumber) + ".txt", "w") - for w in range(0, len(content)): - file.write(content[w] + "\n") + filenumber = int(setcounter) + int(partstart) + file = open("testdata/file" + str(filenumber) + ".txt", "w") + for w in range(0, len(content)): + file.write(content[w] + "\n") + if __name__ == '__main__': - # Getting the user input - print("Hello World") - units = int(input("How many units would you like to generate? ")) - rows = int(input("How many rows should each unit have? ")) - rowLength = int(input("How long should each row be? ")) - cores = int(input("How many cores do you want to use? ")) + # Getting the user input + print("Hello World") + units = int(input("How many units would you like to generate? ")) + rows = int(input("How many rows should each unit have? ")) + rowLength = int(input("How long should each row be? ")) + cores = int(input("How many cores do you want to use? ")) - # Splitting up the units - count = int(0) - partsize = units / cores + # Splitting up the units + count = int(0) + partsize = units / cores - # For benchmarking starting the timer now - start_time = time.time() + # For benchmarking starting the timer now + start_time = time.time() - # Initialize and prepare cores for process - while count < cores: - partstart = partsize * count - globals()["p" + str(count)] = multiprocessing.Process(target=randomI, args=(int(partsize), rows, rowLength, partstart)) - count = count + 1 + # Initialize and prepare cores for process + while count < cores: + partstart = partsize * count + globals()["p" + str(count)] = multiprocessing.Process(target=randomI, args=(int(partsize), rows, rowLength, partstart)) + count = count + 1 - # Starting each core - count = int(0) - while count < cores: - globals()["p" + str(count)].start() - print("Core " + str(count) + " started.") - count = count + 1 + # Starting each core + count = int(0) + while count < cores: + globals()["p" + str(count)].start() + print("Core " + str(count) + " started.") + count = count + 1 - print("Working...") + print("Working...") - # Joining each core for the process - count = int(0) - while count < cores: - globals()["p" + str(count)].join() - count = count + 1 + # Joining each core for the process + count = int(0) + while count < cores: + globals()["p" + str(count)].join() + count = count + 1 - # Finishing up the process - sec = time.time() - start_time - print("Data is generated. Have fun!") - print("randomI took " + str(sec) + " seconds for execution.") + # Finishing up the process + sec = time.time() - start_time + print("Data is generated. Have fun!") + print("randomI took " + str(sec) + " seconds for execution.") diff --git a/src/main.py b/src/main.py index 9a5ddac..6a0e57d 100644 --- a/src/main.py +++ b/src/main.py @@ -1,36 +1,35 @@ #!/usr/bin/env python -#title: main.py -#description: -#author: Conrad Großer -#license: https://github.com/tchemn/miner/blob/master/LICENSE -#date: 02.06.2018 -#version: 0.1 -#usage: PENDING -#notes: -#dependencies: -#known_issues: -#python_version: 3.x -#============================================================================== +# title: main.py +# description: +# author: Conrad Großer +# license: https://github.com/tchemn/miner/blob/master/LICENSE +# date: 02.06.2018 +# version: 0.1 +# usage: PENDING +# notes: +# dependencies: +# known_issues: +# python_version: 3.x +# ============================================================================== # IMPORTS # Importing the time for benchmarking purposes import time -from datetime import date -# CODE (FUNCTIONS) +# CODE # EXECUTION if __name__ == '__main__': - # Print welcoming message - print("Hello world") + # Print welcoming message + print("Hello world") - # For benchmarking starting the timer now - start_time = time.time() + # For benchmarking starting the timer now + start_time = time.time() - # Get parameters, call functions, execute program (...) + # Get parameters, call functions, execute program (...) # BENCHMARKING [END] sec = time.time() - start_time -print("The program took " + str(sec) + " seconds (" + str(sec/60) + " minutes) for execution.") \ No newline at end of file +print("The program took " + str(sec) + " seconds (" + str(sec/60) + " minutes) for execution.") diff --git a/src/modules/importer.py b/src/modules/importer.py index e936f08..fa40b9e 100644 --- a/src/modules/importer.py +++ b/src/modules/importer.py @@ -3,4 +3,4 @@ # Main method of the importer if __name__ == '__main__': - print("IMPORTER MODULE") \ No newline at end of file + print("IMPORTER MODULE") diff --git a/src/template.py b/src/template.py index 9065e5f..822e18e 100644 --- a/src/template.py +++ b/src/template.py @@ -1,16 +1,16 @@ #!/usr/bin/env python -#title: template.py -#description: Template for any programm -#author: Authors seperated by comma -#license: License for the programm -#date: Date of creation -#version: Versionnumber -#usage: Description of how to use the programm quickly -#notes: Notes for parameters, thanks (...) -#dependencies: Preinstalled packages -#known_issues: Known issues in this version -#python_version: Compatible (tested) python version -#============================================================================== +# title: template.py +# description: Template for any programm +# author: Authors seperated by comma +# license: License for the programm +# date: Date of creation +# version: Versionnumber +# usage: Description of how to use the programm quickly +# notes: Notes for parameters, thanks (...) +# dependencies: Preinstalled packages +# known_issues: Known issues in this version +# python_version: Compatible (tested) python version +# ============================================================================== # IMPORTS @@ -23,14 +23,14 @@ from datetime import date # EXECUTION if __name__ == '__main__': - # Print welcoming message - print("Hello world") + # Print welcoming message + print("Hello world") - # For benchmarking starting the timer now - start_time = time.time() + # For benchmarking starting the timer now + start_time = time.time() - # Get parameters, call functions, execute program (...) + # Get parameters, call functions, execute program (...) # BENCHMARKING [END] sec = time.time() - start_time -print("The program took " + str(sec) + " seconds (" + str(sec/60) + " minutes) for execution.") \ No newline at end of file +print("The program took " + str(sec) + " seconds (" + str(sec/60) + " minutes) for execution.")