Got a disk with unallocated space before and after a partition. I'm trying to calculate the size that needs to be in resize-partition. Its probably easier to explain the problem through code.
Output 1 being wrong is understandable since there is unallocated space before the partition. Not too sure what partition.offset can be reliably used...
Oh and we cant use the Get-PartitionSupportedSize cause it seems to mess with some of our other operations. Diskpart is also a no go since this runs a lot and we want to minimize powershell opening other programs.
Basically is there any alternative to Get-PartitionSupportedSize?
$physicalDisk = Get-Disk -Number 2
$partition = Get-Partition -DiskNumber 2
$maxSize = (Get-PartitionSupportedSize -DiskNumber 2).SizeMax
$calcSize = $partition.Size + ($physicalDisk.Size - $physicalDisk.AllocatedSize)
"Output 1"
$maxSize - $calcSize
$calcSize = $partition.Size + ($physicalDisk.Size - $physicalDisk.AllocatedSize) - $partition.Offset
"Output 2"
$maxSize - $calcSize
$calcSize = $physicalDisk.AllocatedSize + $physicalDisk.LargestFreeExtent
"Output 3"
$maxSize - $calcSize
$calcSize = $partition.Size + $physicalDisk.LargestFreeExtent
"Output 4"
$maxSize - $calcSize
Results:
Output 1
-132137984 Output 2 3128320 Output 3
-1065472 Output 4 2079744
Related
I’m trying to construct a Syntax to generate a Syntax in SPSS, but I’m having some issues…
I have an excel file with metadata and I would like to use it in order to make a syntax to extract information from it (like this, if I have a huge database, I just need to keep the excel updated – add/delete variables, etc. - and then run a syntax to extract the needed information for a new syntax).
I also noticed the produced syntax has always around 15Mb, which is a lot (applied to more than 500 lines)!
I don’t use Python due to run syntax in different computers and/or configurations.
Any ideas? Can anyone please help me?
Thank you in advance.
Example:
(test.xlsx – sheet 1)
Var Code Label List Var_label (concatenate Var+Label)
V1 3 Sex 1 V1 “Sex”
V2 1 Work 2 V2 “Work”
V3 3 Country 3 V3 “Country”
V4 1 Married 2 V4 “Married”
V5 1 Kids 2 V5 “Kids”
V6 2 Satisf1 4 V6 “Satisf1”
V7 2 Satisf2 4 V7 “Satisf2”
(information from other file)
List = 1
1 “Male”
2 “Female”
List = 2
1 “Yes”
2 “No”
List = 3
1 “Europe”
2 “America”
3 “Asia”
4 “Africa”
5 “Oceania”
List = 4
1 “Very unsatisfied”
10 “Very satisfied”
I want to make a Syntax that generates a new syntax to apply “VARIABLE LABELS” and “VALUE LABELS”. So, I thought about something like this:
GET DATA
/TYPE=XLSX
/FILE="test.xlsx"
/SHEET=name 'sheet 1'
/CELLRANGE=FULL
/READNAMES=ON
/DATATYPEMIN PERCENTAGE=95.0.
EXECUTE.
STRING vlb (A15) labels (A150) value (A12) lab (A1500) point (A2) separate (A50) space (A2) list1 (A100) list2 (A100).
SELECT IF (Code=1).
COMPUTE vlb = "VARIABLE LABELS".
COMPUTE labels = CONCAT (RTRIM(Var_label)," ").
COMPUTE point = ".".
COMPUTE value = "VALUE LABELS".
COMPUTE lab = CONCAT (RTRIM(Var)," ").
COMPUTE list1 = '1 " Yes "'.
COMPUTE list2 = '2 "No".'.
COMPUTE space = " ".
COMPUTE separate="************************************************.".
WRITE OUTFILE = "list_01.sps" / vlb.
WRITE OUTFILE = "list_01.sps" /labels.
WRITE OUTFILE = "list_01.sps" /point.
WRITE OUTFILE = "list_01.sps" /value.
WRITE OUTFILE = "list_01.sps" /lab.
WRITE OUTFILE = "list_01.sps" /list1.
WRITE OUTFILE = "list_01.sps" /list2.
WRITE OUTFILE = "list_01.sps" /space.
WRITE OUTFILE = "list_01.sps" /separate.
WRITE OUTFILE = "list_01.sps" /space.
If there is only one variable with same list (ex: V1), it works ok. However, if there is more than one variable having the same list, it reproduces the codes as much times as number of variables (Ex: V2, V4 and V5).
What I have (Ex: V2, V4 and V5), after running code above:
VARIABLE LABELS
V2 "Work"
.
VALUE LABELS
V2
1 " Yes "
2 " No "
************************************************.
VARIABLE LABELS
V4 "Married"
.
VALUE LABELS
V4
1 " Yes "
2 " No "
************************************************.
VARIABLE LABELS
V5 "Kids"
.
VALUE LABELS
V5
1 " Yes "
2 " No "
************************************************.
What I would like to have:
VARIABLE LABELS
V2 "Work"
V4 "Married"
V5 "Kids"
.
VALUE LABELS
V2 V4 V5
1 " Yes "
2 " No "
I think there are probably ways to automate the whole process better, including the use of your second data source. But for the scope of this question I will suggest a way to get what you asked for specifically.
The key is to build the command with special conditions for first and last lines:
string cmd1 cmd2 (a200).
sort cases by code.
match files /file=* /first=first /last=last /by code. /* marking first and last lines.
do if first.
compute cmd1="VARIABLE LABELS".
compute cmd2="VALUE LABELS".
end if.
if not first cmd1=concat(rtrim(cmd1), " /"). /* "/" only appears from the second varname.
compute cmd1=concat(rtrim(cmd1), " ", Var_label).
compute cmd2=concat(rtrim(cmd2), " ", Var).
do if last.
compute cmd1=concat(rtrim(cmd1), " .").
compute cmd2=concat(rtrim(cmd2), " ", ' 1 " Yes " 2 "No". ').
end if.
exe.
The commands are now ready, but we don't want to get them mixed up so we'll stack them one under the other, and only then write them out:
add files /file=* /rename cmd1=cmd /file=* /rename cmd2=cmd.
exe.
WRITE OUTFILE = "var definitions.sps" / cmd .
exe.
EDIT:
Note that the code above assumes you've already run a select cases if code = ... and that there is a single code in all the remaining lines.
Note also I added an exe. command at the end - without running that the new syntax will appear empty.
I'm trying to display a statement 1000 times in QBASIC (using for statement). I think the program works properly, but I cannot see the 1000 statements because I cannot scroll up and down in the output window of QBASIC. I can see only the last part of the 1000 statements.
FOR x = 1 TO 1000
PRINT "maydie";
PRINT
NEXT x
That will be very hard. For QBasic you have to know how PRINT works. Than with look you could write an TSR program that does what you want in some other language. Alternative is store everything in array and create you own display routine with scrolling. But with 1000 lines will run into memory restrictions
In short, unless you're using a modern take on QBasic, you can't.
What you can do is print the output to a text file:
OPEN "C:\somefile.txt" FOR OUTPUT AS #1
FOR x = 1 TO 1000
PRINT #1, "maydie":
PRINT
NEXT x
This will write "maydie" to C:\somefile.txt 1000 times. Then use some text editor to view the output. You could even use a program to count the lines of text, something like OPEN "C:|somefile.txt" FOR INPUT AS #1: WHILE NOT EOF(1): INPUT #1, junk$: i = i + 1: WEND: PRINT "There were " + STR$(i) + " lines."
Though the other answerers are correct in saying that it is not inbuilt and hence not possible, I agree that this is very desirable! Consequently, I have time and time again devised scripts based on the following:
DIM text(1 to 1000) AS STRING
'Define text below: Here I've just defined it as every line being
'"maydie" with the value of the line number, but it could be whatever.
FOR i = 1 TO 1000
text(i) = STR$(i) + "maydie"
NEXT i
CLS
position% = 0
FOR i = 1 to 25
LOCATE i, 1: PRINT text(i); SPACE$(80 - LEN(text(i)));
NEXT i
DO
x$=INKEY$
IF x$ <> "" THEN
SELECT CASE x$
CASE CHR$(0) + CHR$(72) 'Up arrow
position% = position% - 1
IF position% < 0 THEN position% = 0
CASE CHR$(0) + CHR$(80) 'Down arrow
position% = position% + 1
IF position% > 975 THEN position% = 975
CASE CHR$(0) + "I" 'Page Up
position% = position% - 24
IF position% < 0 THEN position% = 0
CASE CHR$(0) + "Q" 'Page Down
position% = position% + 24
IF position% > 975 THEN position% = 975
CASE CHR$(27) 'ENDS the Program on ESC key.
END
END SELECT
FOR i = 1 to 25
LOCATE i, 1: PRINT text(i + position%); SPACE$(80 - LEN(text(i + position%)));
NEXT i
END IF
LOOP
Tested and works! If you want to use it multiple times in your program for multiple different text blocks, you can just turn it into a function and pass it the variables you want.
The simplified loop below exits at random times when I use the set -e option. If I remove the set -e option it always completes. I would like to use the set -e option if possible but so far I am at a loss as to why it is exiting and why it happens at random loop iterations each time I run it (try it!). As you can see the only commands are let and echo. Why would the let or echo commands return a non-zero code at random times, or is something else going on?
#!/bin/bash
# Do Release configuration builds so we can set the build parameters
set -e
CFG=Release
for CASE in {0..511}
do
# CASE [0...511] iterate
# MMMM [2...255] random test cases
# NNNN [1..MMMM) random test cases
# RRRR [0...255] random test cases
# XXXX [0...255] random test cases
# DSXX [1...128] random test cases
# OASM [1...255] random test cases
# OLSM [1...255] random test cases
let "MMMM = $RANDOM % 254 + 2"
let "NNNN = $RANDOM % ($MMMM - 1) + 1"
let "RRRR = $RANDOM % 256"
let "XXXX = $RANDOM % 256"
let "DSXX = $RANDOM % 128 + 1"
let "OASM = $RANDOM % 255 + 1"
let "OLSM = $RANDOM % 255 + 1"
echo CFG = $CFG, CASE = $CASE, MMMM = $MMMM, NNNN = $NNNN, RRRR = $RRRR, XXXX = $XXXX, DSXX = $DSXX, OASM = $OASM, and OLSM = $OLSM
# Some other stuff (build and test), that is not causing the problem, goes here
done
# Some other stuff, that is not causing the problem, goes here
exit 0
Append || true to your let commands or use $((...)) for calculations.
From help let:
Exit Status: If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise.
I'm trying to make a real time process list at python. I want that every 5 seconds the list i made will be updated. Moreover I want to get cpu time usage for each process but the output is 0 for some reason....
This is a part from the code:
def start(self):
while True:
#-----------------------------------------------------------------------------
processes = []
for process in self.wmi_object.Win32_Process ():
size = int(process.WorkingSetSize) / 1024
try:
p = psutil.Process(process.ProcessId)
cpu_percent = 0# p.cpu_percent(interval=1)
processes.append( process.Name + " " + str(process.ProcessId) + " " + str(size) + "kb" + " " + str(cpu_percent) )
except : pass
self.clientNetwork.send ( pickle.dumps(processes) )
time.sleep(5)
I don't know how to make this a right. Every 5 second the processes just added to the list the previous stay instead of being deleted.
Appriciate help :)
I've been working on a NetLogo model simulating entrepreneurs based on Nelson-Winter model. In the model, every tick there is a Demand and Supply for some product,then the price=Demand/Supply, so every tick the entrepreneurs have a chance to set up a company and make money, the probability of setting uo a companies is effected by the revenue of other companies set up by the entrepreneurs in the same group, entrepreneurs in the same group share the same gamma and lambda,gamma decide the proportion of profit invested in R&D(innovation and imitation),the lambda decided the proportion of R & D funding invested in the innovation. The success of RD will enhance the production.Finally it will returned the result of companies averaged by group, the companies in the same group will have the same companyNO and same gamma and lambda.
This process seems to work fine but it runs exceedingly slow, to the point that I'm worried I won't be able to feasibly run many simulations. Any ideas on how to speed up this process? In the earlier version model without group the model works really fast, so I think the problem lies in the grouping. The model code is getting pretty long, so I just added the part related to the grouping. I can provide more code to someone if the problem seems to lie elsewhere. Any help would be much appreciated!
globals[
S;;aggregate supply
SafterDie
D;;aggregate demand
P;;price of demand,P=D/S
g b eta;;used for get demand
file1
file2
totalGamma
totalLambda
NO
]
breed [entrepreneurs a-entrepreneur]
breed [companies a-company]
entrepreneurs-own[
humanCapital
timesOfChuangYe
chuangYe?;;chuang ye mei de
gaiLv
renGamma
renLambda
renNO
]
companies-own[
humanCapital
tempHumanCapital;;20140516
oldHumanCapital
initialCap
initialTech
companiesNO
capitalK;;capital K,nedd money c*K
gamma;;money uesd for R&D
lambda;;money used for innovation in terms of imitation
lifeLength
RecentRevenue;;profit every tick
production;;production of the tick
profit
accumulatedInnovation
accumulatedImitation
]
to setup
foreach n-values NoOfgroup [?] [
set bigGamma (random-in-range 0.4 1);;money uesd for innovation
set bigLambda (random-in-range 0.1 1);;money used for innovation VS imitation
set NO (? + 1)
create-entrepreneurs numberOfentreprenursInEveryGroup [ entrepreneur-setup ]
]
to entrepreneur-setup ;; turtle procedure
set color red
set shape "line";;line
move-to one-of patches
set humanCapital random-in-range 0 1
set chuangYe? 0;;if Entrepreneurship,0 no,1 yes
set timesOfChuangYe 0;;Entrepreneurship times
set renGamma bingGamma
set renLambda bingLambda
set renNO NO
end
to ifChuangYe
ask entrepreneurs with [chuangYe? = 0]
[
let node1 self
set gaiLv 0;;probability of entrepreneurship
getProbabilitiOfEntrepreueur node1
if (random-float 1 <= gaiLv)[
set chuangYe? 1
set timesOfChuangYe (timesOfChuangYe + 1)
hatch-companies 1 [
set color yellow
set shape "house"
create-link-with node1 [set color yellow]
set humanCapital ([humanCapital] of node1);;!!!
set companyNO ([renNO] of node1)
set gamma ([renGamma] of node1);;money uesd for RD
set lambda ([renLambda] of node1);;money used for innovation VS imitation
set initialTech humanCapital
set tempHumanCapital humanCapital
set oldHumanCapital humanCapital
company-setup
]
]
]
end
to getProbabilitiOfEntrepreueur [node1]
ask node1[
let number renNO
let co1 no-turtles
let en1 entrepreneurs with [renNO = number];;get entrepreneur
ask en1 [
set co1 link-neighbors;;get company
]
let total 0
ask co1 [;;to link
if lifeLength != 0 [
let k lifeLength
let singleRevenue 0
if lifeLength >= 6 [set k 6]
foreach n-values k [?] [
set singleRevenue (singleRevenue + (item ? RecentRevenue)/ (? + 1))
];;RecentRevenue is a list to collect a company's profit of every tick
set total total + singleRevenue
]
]
set gaiLv (1 / 50 * total + 5 / 100)
;;show gaiLv
]
end
to imitation
let newH 0
ask companies[
set accumulatedImitation (accumulatedImitation + (1 - lambda)* gamma * profit)
if accumulatedImitation >= 0.3 * (capitalK ^ 3) [
let co2 companies with [companyNO = companyNo]
set newH max ([humanCapital] of co2)
if newH > humanCapital [set humanCapital newH set imNO imNO + 1]
set accumulatedImitation (accumulatedImitation - 0.3 * (capitalK ^ 3))
]
]
end