Commit bfbf3e56167b0f8650cbbffcddd4bb4a9281adf6
1 parent
3df2cc2b
Exists in
master
and in
68 other branches
ENH: Memory predict in the Linux and enhancemented Windows #76
Showing
1 changed file
with
34 additions
and
69 deletions
Show diff stats
invesalius/utils.py
| @@ -22,6 +22,9 @@ import subprocess | @@ -22,6 +22,9 @@ import subprocess | ||
| 22 | import re | 22 | import re |
| 23 | import sys | 23 | import sys |
| 24 | 24 | ||
| 25 | +if sys.platform == 'win32': | ||
| 26 | + import wmi | ||
| 27 | + | ||
| 25 | 28 | ||
| 26 | def debug(error_str): | 29 | def debug(error_str): |
| 27 | from project import Project | 30 | from project import Project |
| @@ -95,7 +98,8 @@ def PredictingMemory(qtd, x, y, p): | @@ -95,7 +98,8 @@ def PredictingMemory(qtd, x, y, p): | ||
| 95 | 98 | ||
| 96 | if (sys.platform == 'win32'): | 99 | if (sys.platform == 'win32'): |
| 97 | 100 | ||
| 98 | - physical_memory = GetWindowsInformation()[3] | 101 | + #physical_memory in Byte |
| 102 | + physical_memory = GetWindowsInformation()[0] | ||
| 99 | 103 | ||
| 100 | if (platform.architecture()[0] == '32bit'): | 104 | if (platform.architecture()[0] == '32bit'): |
| 101 | #(314859200 = 300 MB) | 105 | #(314859200 = 300 MB) |
| @@ -109,14 +113,18 @@ def PredictingMemory(qtd, x, y, p): | @@ -109,14 +113,18 @@ def PredictingMemory(qtd, x, y, p): | ||
| 109 | return (x, y) | 113 | return (x, y) |
| 110 | else: #64 bits architecture | 114 | else: #64 bits architecture |
| 111 | 115 | ||
| 112 | - if (physical_memory <= 2.0) and (qtd <= 1200): | ||
| 113 | - porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | 116 | + #2147483648 byte = 2.0 GB |
| 117 | + #4294967296 byte = 4.0 GB | ||
| 114 | 118 | ||
| 115 | - elif(physical_memory <= 2.0) and (qtd > 1200): | ||
| 116 | - porcent = 1.5 + (m - 314859200) / 26999999 * 0.03 | 119 | + if (physical_memory <= 2147483648) and (qtd <= 1200): |
| 120 | + porcent = 1.5 + (m - 314859200) / 26999999 * 0.04 | ||
| 117 | 121 | ||
| 118 | - elif(physical_memory > 2.0) and (physical_memory <= 4.0) and (qtd <= 1200): | ||
| 119 | - porcent = 1.5 + (m - 314859200) / 26999999 * 0.01 | 122 | + elif(physical_memory <= 2147483648) and (qtd > 1200): |
| 123 | + porcent = 1.5 + (m - 314859200) / 26999999 * 0.05 | ||
| 124 | + | ||
| 125 | + elif(physical_memory > 2147483648) and \ | ||
| 126 | + (physical_memory <= 4294967296) and (qtd <= 1200): | ||
| 127 | + porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | ||
| 120 | 128 | ||
| 121 | else: | 129 | else: |
| 122 | return (x,y) | 130 | return (x,y) |
| @@ -125,22 +133,22 @@ def PredictingMemory(qtd, x, y, p): | @@ -125,22 +133,22 @@ def PredictingMemory(qtd, x, y, p): | ||
| 125 | 133 | ||
| 126 | elif(sys.platform == 'linux2'): | 134 | elif(sys.platform == 'linux2'): |
| 127 | 135 | ||
| 128 | - physical_memory = GetLinuxInformation()[2] | 136 | + physical_memory = GetLinuxInformation()[0] |
| 129 | 137 | ||
| 130 | if (platform.architecture()[0] == '32bit'): | 138 | if (platform.architecture()[0] == '32bit'): |
| 131 | # 839000000 = 800 MB | 139 | # 839000000 = 800 MB |
| 132 | - if (m <= 839000000) and (physical_memory <= 2.0): | 140 | + if (m <= 839000000) and (physical_memory <= 2147483648): |
| 133 | return (x,y) | 141 | return (x,y) |
| 134 | - elif (m > 839000000) and (physical_memory <= 2.0) and (qtd <= 1200): | 142 | + elif (m > 839000000) and (physical_memory <= 2147483648) and (qtd <= 1200): |
| 135 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | 143 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 |
| 136 | else: | 144 | else: |
| 137 | return (x,y) | 145 | return (x,y) |
| 138 | 146 | ||
| 139 | else: | 147 | else: |
| 140 | 148 | ||
| 141 | - if (m <= 839000000) and (physical_memory <= 2.0): | 149 | + if (m <= 839000000) and (physical_memory <= 2147483648): |
| 142 | return (x, y) | 150 | return (x, y) |
| 143 | - elif (m > 839000000) and (physical_memory <= 2.0) and (qtd <= 1200): | 151 | + elif (m > 839000000) and (physical_memory <= 2147483648) and (qtd <= 1200): |
| 144 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | 152 | porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 |
| 145 | else: | 153 | else: |
| 146 | return (x,y) | 154 | return (x,y) |
| @@ -148,17 +156,7 @@ def PredictingMemory(qtd, x, y, p): | @@ -148,17 +156,7 @@ def PredictingMemory(qtd, x, y, p): | ||
| 148 | return (x/porcent, y/porcent) | 156 | return (x/porcent, y/porcent) |
| 149 | 157 | ||
| 150 | elif(sys.platform == 'darwin'): | 158 | elif(sys.platform == 'darwin'): |
| 151 | - | ||
| 152 | - physical_memory = GetDarwinInformation() | ||
| 153 | - | ||
| 154 | - if (m <= 839000000) and (physical_memory <= 2.0): | ||
| 155 | - return (x, y) | ||
| 156 | - elif (m > 839000000) and (physical_memory <= 2.0) and (qtd <= 1200): | ||
| 157 | - porcent = 1.5 + (m - 314859200) / 26999999 * 0.02 | ||
| 158 | - else: | ||
| 159 | - return (x, y) | ||
| 160 | - | ||
| 161 | - return (x/porcent,y/porcent) | 159 | + return (x/2,y/2) |
| 162 | 160 | ||
| 163 | 161 | ||
| 164 | 162 | ||
| @@ -174,42 +172,14 @@ def BytesConvert(bytes): | @@ -174,42 +172,14 @@ def BytesConvert(bytes): | ||
| 174 | 172 | ||
| 175 | 173 | ||
| 176 | def GetWindowsInformation(): | 174 | def GetWindowsInformation(): |
| 175 | + computer = wmi.WMI() | ||
| 176 | + for i in computer.Win32_ComputerSystem (): | ||
| 177 | + memory = int(i.TotalPhysicalMemory) | ||
| 177 | 178 | ||
| 178 | - command = "systeminfo" | ||
| 179 | - | ||
| 180 | - startupinfo = subprocess.STARTUPINFO() | ||
| 181 | - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW | ||
| 182 | - info = subprocess.Popen([command], startupinfo=startupinfo, | ||
| 183 | - stdout=subprocess.PIPE).communicate() | 179 | + information = (memory,) |
| 184 | 180 | ||
| 185 | - lines = info[0].splitlines() | 181 | + return information |
| 186 | 182 | ||
| 187 | - #Architecture of the system, x86 or x64 | ||
| 188 | - architecture = lines[14] | ||
| 189 | - architecture = re.findall('[0-9]+', architecture)[0] | ||
| 190 | - architecture = "x" + architecture | ||
| 191 | - | ||
| 192 | - #Number of processors or number of nucleus | ||
| 193 | - number_processors = lines[15] | ||
| 194 | - number_processors = re.findall('[0-9]+', number_processors)[0] | ||
| 195 | - | ||
| 196 | - #Clock of the processor in Mhz | ||
| 197 | - processor_clock = lines[16] | ||
| 198 | - processor_clock = re.findall('~[0-9]+', processor_clock)[0] | ||
| 199 | - processor_clock = float(re.findall('[0-9]+', processor_clock)[0]) | ||
| 200 | - | ||
| 201 | - #Total of Physical Memory in MB | ||
| 202 | - total_physical_memory = lines[24 + (int(number_processors) - 1)] | ||
| 203 | - total_physical_memory = float(re.findall('[0-9.]+', total_physical_memory)[0]) | ||
| 204 | - | ||
| 205 | - #Total of Physical Memory Avaliable in MB | ||
| 206 | - available_physical_memory = lines[25 + (int(number_processors) - 1)] | ||
| 207 | - available_physical_memory = float(re.findall('[0-9.]+', | ||
| 208 | - available_physical_memory)[0]) | ||
| 209 | - | ||
| 210 | - return (architecture, number_processors, | ||
| 211 | - processor_clock, total_physical_memory, | ||
| 212 | - available_physical_memory) | ||
| 213 | 183 | ||
| 214 | def GetDarwinInformation(): | 184 | def GetDarwinInformation(): |
| 215 | memory = 2.0 | 185 | memory = 2.0 |
| @@ -217,19 +187,14 @@ def GetDarwinInformation(): | @@ -217,19 +187,14 @@ def GetDarwinInformation(): | ||
| 217 | 187 | ||
| 218 | 188 | ||
| 219 | def GetLinuxInformation(): | 189 | def GetLinuxInformation(): |
| 220 | - | ||
| 221 | - #Architecture of the system, x86 or x64 | ||
| 222 | - architecture = LinuxCommand("uname -m") | ||
| 223 | - architecture = architecture[0].splitlines()[0] | ||
| 224 | - | ||
| 225 | - #Clock of the processor in Mhz | ||
| 226 | - processor_clock = LinuxCommand("more /proc/cpuinfo") | ||
| 227 | - processor_clock = processor_clock[0].splitlines() | ||
| 228 | - processor_clock = float(re.findall('[0-9.]+', processor_clock[6])[0]) | ||
| 229 | - | ||
| 230 | - | ||
| 231 | - #processor_clock = float(re.findall('[0-9]+', processor_clock)[0]) | ||
| 232 | - return (architecture, processor_clock, 2.0) | 190 | + #Getting memory |
| 191 | + with open('/proc/meminfo') as f: | ||
| 192 | + for i in f: | ||
| 193 | + if i.startswith('MemTotal'): | ||
| 194 | + # To translate from KB to Bytes | ||
| 195 | + mem = int(i.split()[1]) * 1024 | ||
| 196 | + | ||
| 197 | + return (mem,) | ||
| 233 | 198 | ||
| 234 | 199 | ||
| 235 | def LinuxCommand(command): | 200 | def LinuxCommand(command): |