My AutoIt script should predict when a process will complete by saying The process will be complete at 3:18:24 PM. But that is not happening. It takes these input values:
Starting time
Starting percentage
Current time
Current percentage
It displays:
"The extraction will be complete at 0".
I isolated the problem to _DateDiff(). I thought the first parameter was n for difference in minutes. But it returns 0 when I pass the next two parameters (date values spaced sixty minutes apart). Here's the code:
GUICreate("Completion Time Predictor", 300, 300)
;Here I enter the starting time and percentage
GUICtrlCreateLabel("Enter the start time:", 10, 10, 270, 29)
$StartTime = GUICtrlCreateDate("", 10, 40, 270, 21, $DTS_TIMEFORMAT)
GUICtrlCreateLabel("Enter the start percentage:", 10, 70, 270, 29)
Local $StartPercent = GUICtrlCreateInput("", 10, 100, 270, 21)
;Here I enter the current time and percentage
GUICtrlCreateLabel("Enter the current time:", 10, 130, 270, 29)
$CurrentTime = GUICtrlCreateDate("", 10, 160, 270, 21, $DTS_TIMEFORMAT)
GUICtrlCreateLabel("Enter the current percentage:", 10, 190, 270, 29)
Local $CurrentPercent = GUICtrlCreateInput("", 10, 220, 270, 21)
Local $CTRL_a = GUICtrlCreateButton("Calculate", 10, 260, 280, 21)
GUISetState()
Local $msg
Do
$msg = GUIGetMsg()
Select
Case $msg = $CTRL_a
$PercentChange = GUICtrlRead($CurrentPercent) - GUICtrlRead($StartPercent)
;This seems to be where everything is going wrong
$ChangePerMinute = $PercentChange / _DateDiff('n', GUICtrlRead($StartTime), GUICtrlRead($CurrentTime))
$MinutesRemaining = (100 - GUICtrlRead($CurrentPercent)) / $ChangePerMinute
$EndTime = _DateAdd('n', $MinutesRemaining, GUICtrlRead($CurrentTime))
MsgBox($MB_OK, "Predicted Completion Time:", "The extraction will be complete at " & $EndTime)
EndSelect
Until $msg = $GUI_EVENT_CLOSE
I have no idea what you are doing, but maybe this helps you finding the problem
#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
GUICreate("Completion Time Predictor", 300, 300)
;Here I enter the starting time and percentage
GUICtrlCreateLabel("Enter the start time:", 10, 10, 270, 29)
$StartTime = GUICtrlCreateDate("", 10, 40, 270, 21, $DTS_TIMEFORMAT)
GUICtrlCreateLabel("Enter the start percentage:", 10, 70, 270, 29)
Local $StartPercent = GUICtrlCreateInput("0", 10, 100, 270, 21)
;Here I enter the current time and percentage
GUICtrlCreateLabel("Enter the current time:", 10, 130, 270, 29)
$CurrentTime = GUICtrlCreateDate("", 10, 160, 270, 21, $DTS_TIMEFORMAT)
GUICtrlSetData(-1, _NowCalcDate() & ' ' & #HOUR + 1 & ":" & #MIN & ':' & #SEC)
GUICtrlCreateLabel("Enter the current percentage:", 10, 190, 270, 29)
Local $CurrentPercent = GUICtrlCreateInput("10", 10, 220, 270, 21)
Local $CTRL_a = GUICtrlCreateButton("Calculate", 10, 260, 280, 21)
GUISetState()
Local $msg
Do
$msg = GUIGetMsg()
Select
Case $msg = $CTRL_a
ConsoleWrite(_NowCalcDate() & ' ' & GUICtrlRead($StartTime) & " " & _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime) & #CRLF)
$PercentChange = GUICtrlRead($CurrentPercent) - GUICtrlRead($StartPercent)
ConsoleWrite("% Change: " & $PercentChange & #CRLF)
;This seems to be where everything is going wrong
$diff_min = _DateDiff('n', _NowCalcDate() & ' ' & GUICtrlRead($StartTime), _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime))
ConsoleWrite("Diff in Min: " & $diff_min & #CRLF)
$ChangePerMinute = $PercentChange / $diff_min
ConsoleWrite("Change / min : " & $ChangePerMinute & #CRLF)
$MinutesRemaining = (100 - GUICtrlRead($CurrentPercent)) / $ChangePerMinute
ConsoleWrite("MinutesRemaining : " & " " & $MinutesRemaining & #CRLF)
$EndTime = _DateAdd('n', $MinutesRemaining, _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime))
MsgBox($MB_OK, "Predicted Completion Time:", "The extraction will be complete at " & $EndTime)
EndSelect
Until $msg = $GUI_EVENT_CLOSE
Related
wanted to discuss one issue i am getting while using the google ortools.
Problem: status of the solution is coming INFEASIBLE. but solution is feasible as per my understandings.
below is the sample.py used
import collections
from ortools.sat.python import cp_model
class SolutionPrinter(cp_model.CpSolverSolutionCallback):
"""Print intermediate solutions."""
def __init__(self):
cp_model.CpSolverSolutionCallback.__init__(self)
self.__solution_count = 0
def on_solution_callback(self):
"""Called at each new solution."""
print('Solution %i, time = %f s, objective = %i' %
(self.__solution_count, self.WallTime(), self.ObjectiveValue()))
self.__solution_count += 1
def flexible_jobshop():
"""Solve a small flexible jobshop problem."""
# Data part.
jobs = [
[ # Job 0 (machine_id, processingtime, starttime,endtime)
[(0, 65, 0, 72), (1, 65, 0, 72), (2, 65, 0, 72)], # task 0 with 3 alternatives
[(3, 170, 0, 240), (4, 170, 0, 240), (5, 170, 0, 240)] # task 1 with 3 alternatives
],
[ # Job 1
[(0, 25, 0, 120), (1, 25, 0, 120), (2, 25, 0, 120)],
[(3, 168, 0, 288), (4, 168, 0, 288), (5, 168, 0, 288)]
],
[ # Job 2
[(0, 34, 0, 480), (1, 34, 0, 480), (2, 34, 0, 480)],
[(3, 32, 0, 504), (4, 32, 0, 504), (5, 32, 0, 504)]
],
[ # Job 3
[(0, 39, 0, 600), (1, 39, 0, 600), (2, 39, 0, 600)],
[(3, 93, 0, 696), (4, 93, 0, 696), (5, 93, 0, 696)]
]
]
# from data import Data
# jobs = Data().p3
# print(jobs)
num_jobs = len(jobs)
all_jobs = range(num_jobs)
num_machines = 3
all_machines = range(num_machines)
# Model the flexible jobshop problem.
model = cp_model.CpModel()
horizon = 0
for job in jobs:
for task in job:
max_task_duration = 0
for alternative in task:
max_task_duration = max(max_task_duration, alternative[1])
horizon += max_task_duration
print('Horizon = %i' % horizon)
# Global storage of variables.
intervals_per_resources = collections.defaultdict(list)
starts = {} # indexed by (job_id, task_id).
presences = {} # indexed by (job_id, task_id, alt_id).
job_ends = []
# Scan the jobs and create the relevant variables and intervals.
for job_id in all_jobs:
job = jobs[job_id]
num_tasks = len(job)
previous_end = None
for task_id in range(num_tasks):
task = job[task_id]
min_duration = task[0][1]
max_duration = task[0][1]
num_alternatives = len(task)
all_alternatives = range(num_alternatives)
for alt_id in range(1, num_alternatives):
alt_duration = task[alt_id][1]
min_duration = min(min_duration, alt_duration)
max_duration = max(max_duration, alt_duration)
# Create main interval for the task.
suffix_name = '_j%i_t%i' % (job_id, task_id)
# start = model.NewIntVar(task[0][2], horizon, 'start' + suffix_name)
start = model.NewIntVar(0, horizon, 'start' + suffix_name)
duration = model.NewIntVar(min_duration, max_duration,
'duration' + suffix_name)
end = model.NewIntVar(0, horizon, 'end' + suffix_name)
# end = model.NewIntVar(task[0][3], horizon, 'end' + suffix_name)
interval = model.NewIntervalVar(start, duration, end,
'interval' + suffix_name)
# Store the start for the solution.
starts[(job_id, task_id)] = start
# Add precedence with previous task in the same job.
if previous_end is not None:
model.Add(start >= previous_end)
previous_end = end
# Create alternative intervals.
if num_alternatives > 1:
l_presences = []
for alt_id in all_alternatives:
alt_suffix = '_j%i_t%i_a%i' % (job_id, task_id, alt_id)
l_presence = model.NewBoolVar('presence' + alt_suffix)
l_start = model.NewIntVar(0, horizon, 'start' + alt_suffix)
l_duration = task[alt_id][0]
l_end = model.NewIntVar(0, horizon, 'end' + alt_suffix)
l_interval = model.NewOptionalIntervalVar(
l_start, l_duration, l_end, l_presence,
'interval' + alt_suffix)
l_presences.append(l_presence)
# Link the master variables with the local ones.
model.Add(start == l_start).OnlyEnforceIf(l_presence)
model.Add(duration == l_duration).OnlyEnforceIf(l_presence)
model.Add(end == l_end).OnlyEnforceIf(l_presence)
# Add the local interval to the right machine.
intervals_per_resources[task[alt_id][1]].append(l_interval)
# Store the presences for the solution.
presences[(job_id, task_id, alt_id)] = l_presence
# Select exactly one presence variable.
model.AddExactlyOne(l_presences)
else:
intervals_per_resources[task[0][1]].append(interval)
presences[(job_id, task_id, 0)] = model.NewConstant(1)
job_ends.append(previous_end)
# Create machines constraints.
for machine_id in all_machines:
intervals = intervals_per_resources[machine_id]
if len(intervals) > 1:
model.AddNoOverlap(intervals)
# Makespan objective
makespan = model.NewIntVar(0, horizon, 'makespan')
model.AddMaxEquality(makespan, job_ends)
model.Minimize(makespan)
# Solve model.
solver = cp_model.CpSolver()
solution_printer = SolutionPrinter()
status = solver.Solve(model, solution_printer)
# Print final solution.
for job_id in all_jobs:
print('Job %i:' % job_id)
for task_id in range(len(jobs[job_id])):
start_value = solver.Value(starts[(job_id, task_id)])
machine = -1
duration = -1
selected = -1
for alt_id in range(len(jobs[job_id][task_id])):
if solver.Value(presences[(job_id, task_id, alt_id)]):
duration = jobs[job_id][task_id][alt_id][0]
machine = jobs[job_id][task_id][alt_id][1]
selected = alt_id
print(
' task_%i_%i starts at %i (alt %i, machine %i, duration %i)' %
(job_id, task_id, start_value, selected, machine, duration))
print('Solve status: %s' % solver.StatusName(status))
print('Optimal objective value: %i' % solver.ObjectiveValue())
print('Statistics')
print(' - conflicts : %i' % solver.NumConflicts())
print(' - branches : %i' % solver.NumBranches())
print(' - wall time : %f s' % solver.WallTime())
flexible_jobshop()
for this data set, it is giving infeasible solution.
Not sure what i m doing wrong here.
please guide.
Utils_Get_Epoch(Utils_tm_t *tm)
{
uint32_t epoch = 0;
const int mon_days[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
uint16_t tyears, i, leaps;
uint32_t tdays, thours;
tyears = tm->tm_year - 70;
leaps = (tyears + 2) / 4;
i = (tm->tm_year - 100) / 100;
leaps -= ((i/4) * 3 + i%4);
tdays = mon_days[tm->tm_mon];
tdays += tm->tm_mday - 1;
tdays = tdays + tyears * 365 + leaps;
thours = tm->tm_hour;
epoch = (tdays * 86400) + (thours * 3600) + (tm->tm_min * 60) + tm->tm_sec;
return epoch;
}
turns out the return value is always 1 day ahead the current date, can anyone help me with it?
I have some powershell code that returns a load of computers to an array from a SQL query.
The query return vary in the total number of members. I shuffle the array also.
I want to take that array and split it into four or five smaller arrays by percentage. I want to define the percentages beforehand. For example, I might want to see 25%, 25%, 25%, 25%. Another time I want to see 10%, 30%, 30%, 40% or another 5%, 35%, 30%, 30%.
$phasepercents = 0.1,0.2,0.2,0.25,0.25 #Percentage of machines in each
group
# AD groups to be created, Group5 is not needed as all EUC machines will be
# added in the final round
$Phase0group = #()
$Phase1group = #()
$Phase2group = #()
$Phase3group = #()
$Phase4group = #()
$computers = my sql query with returned computers
$totalmachines = $computers.count #Total No of machine in the collection
$Machinesineachgroup = #()
$phasestartnumbers = #()
# work out the percentages
$counter = 0
foreach ($phasepercent in $phasepercents)
{
$value = $phasepercent *= $totalmachines
$value = [Math]::floor($value)
$Machinesineachgroup += $value
#WriteToLog "[INFO]`t,Machines in Phase$counter is $value"
$counter +=1
}
WriteToLog "[INFO-S]`t Total Machines in each phases $Machinesineachgroup"
this will break your collection into batch sizes based on the % in the $PercentageList and then store those batches into an array of arrays. you could also modify it to store the arrays in properties of a custom object OR into a hashtable if desired. [grin]
$MasterList = 1..100
$PercentageList = 10, 30, 20, 40
$Index = 0
$BatchList = foreach ($PL_Item in $PercentageList)
{
$BatchSize = [math]::Round($MasterList.Count * $PL_Item / 100, 0)
# the leading comma forces PoSh to NOT unroll the array
# instead, it is stored as whole
,$MasterList[$Index..($Index + $BatchSize - 1)]
$Index = $Index + $BatchSize
}
$BatchList[0] -join ', '
'=' * 30
$BatchList.ForEach({$_ -join ', '})
output ...
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
==============================
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100
I keep getting an error message when trying to use VennDiagram in R. Below is my posted code:
draw.quintuple.venn(area1 = 578, area2 = 519, area3 = 212, area4 = 402, area5 = 172, n12 = 366, n15 = 97, n13 =149, n14 = 284, n23 = 103, n24 = 202, n25 = 125, n35 = 31, n34= 12, n45 = 27, n123 = 80, n124 = 161, n125 = 84, n134 = 8, n135 = 25, n145 = 20, n234 = 5, n235 = 24, n245 = 21, n345 = 1, n1234 = 5, n1345 = 21, n1245 = 16, n1235 = 0, n2345 = 0, n12345 = 0, category = c("1", "2", "3", "4", "5"), lty = "blank", fill = c("skyblue", "pink1", "mediumorchid", "yellow", "orange"))
Error:
ERROR [2018-07-09 13:37:19] Impossible: a11 <- n23 - a21 - a22 - a24 -
a26 - a29 - a30 - a31 produces negative area Error in
draw.quintuple.venn(area1 = 578, area2 = 519, area3 = 212, area4 =
402, : Impossible: a11 <- n23 - a21 - a22 - a24 - a26 - a29 - a30
- a31 produces negative area
What am I doing wrong?
I double checked and made sure the values are all correct.
I do not think that this package is well documented. A look at the source code shows that the meaning of nxxxxx is not the obvious one. For instance n135 means "how many elements belong to at least groups 1, 3 and 5". When you want to draw the diagram, the package calculates how many of those n135 also belong to other groups (i. e., n1235, n1345 and n12345) and substracts them.
What seems to be happening here is that you interpret n135 as "how many elements only belong to sets 1, 3 and 5" (that would have also been my guess). If you want to use those numbers directly, you should write:
draw.quintuple.venn(area.vector = c(578, 519, 212, 402, 172, 31, 97, 284, 366, 125, 103, 149, 12, 202, 27, 1, 25, 20, 161, 84, 24, 80, 8, 5, 21, 0, 21, 16, 0, 5, 0), category = c("1", "2", "3", "4", "5"), lty = "blank", fill = c("skyblue", "pink1", "mediumorchid", "yellow", "orange"), direct.area = T)
The order of the numbers is taken directly from the source code, I have not seen it documented. Let us call a135 "how many elements only belong to sets 2, 3 and 5". With this in mind, the order would be:
a1, a2, a3, a4, a5, a35, a15, a14, a12, a25, a23, a13, a34, a24, a45, a345, a135, a145, a124, a125, a235, a123, a134, a234, a245, a2345, a1345, a1245, a1235, a1234, a12345
If you prefer to use the n135 notation, you would need to transform your data, so that n135 = a135 + a1235 + a1345 + a12345, and so forth. In your case, n135 = 25 + 0 + 21 + 0 = 36.
Although not part of the question, you can also use my nVennR package for a proportional representation. The order of the numbers is documented in the help and the vignette, and you can also enter raw sets rather than numbers:
library(nVennR)
myV <- createVennObj(nSets = 5, sNames = c('1', '2', '3', '4', '5'), sSizes = c(0, 172, 402, 27, 212, 31, 12, 1, 519, 125, 202, 21, 103, 24, 5, 0, 578, 97, 284, 20, 149, 25, 8, 21, 366, 84, 161, 16, 80, 0, 5, 0))
myV <- plotVenn(nVennObj = myV, setColors = c("skyblue", "pink1", "mediumorchid", "yellow", "orange"), borderWidth = 0)
And the result:
I'm new to python and MyHDL so I started by converting old VHDL projects to MyHDL. This project is a vga timer that can accept any width, height, and frequency (given that they actually work with monitors). It doesn't successfully convert to either VHDL or Verilog because of the statements:
h_count.val.max # line 30
v_count.val.max # line 33
I can print their values just fine so they definitely evaluate to integers, but if I replace them with their literal values then it properly converts. I couldn't find anything about this in the myhdl issue tracker, but I don't want to add a false issue because of a newbie's mistake. Is there a proper way to use Signal.val.max or do I just avoid it? Here's the full code:
from myhdl import Signal, intbv, always_comb, always, toVHDL
def vga_timer(clk, x, y, h_sync, v_sync, vidon, width=800, height=600, frequency=72,
left_buffer=0, right_buffer=0, top_buffer=0, bottom_buffer=0):
# load vga constants by resolution
resolution = (width, height, frequency)
supported_resolutions = {(640, 480, 60): (16, 96, 48, 10, 2, 33, 0),
(800, 600, 60): (40, 128, 88, 1, 4, 23, 1),
(800, 600, 72): (56, 120, 64, 37, 6, 23, 1),
(1024, 768, 60): (24, 136, 160, 3, 6, 29, 0),
(1280, 720, 60): (72, 80, 216, 3, 5, 22, 1),
(1920, 1080, 60): (88, 44, 148, 4, 5, 36, 1)}
assert resolution in supported_resolutions, "%ix%i # %ifps not a supported resolution" % (width, height, frequency)
screen_constants = supported_resolutions.get(resolution)
# h for horizontal variables and signals, v for vertical constants and signals
h_front_porch, h_sync_width, h_back_porch, v_front_porch, v_sync_width, v_back_porch, polarity = screen_constants
h_count = Signal(intbv(0, 0, width + h_front_porch + h_sync_width + h_back_porch))
v_count = Signal(intbv(0, 0, height + v_front_porch + v_sync_width + v_back_porch))
print(h_count.val.max)
print(v_count.val.max)
#always(clk.posedge)
def counters():
h_count.next = h_count + 1
v_count.next = v_count
if h_count == 1040 - 1: # h_count.val.max - 1:
h_count.next = 0
v_count.next = v_count + 1
if v_count == 666 - 1: # v_count.val.max - 1:
v_count.next = 0
# determines h_sync and v_sync
#always_comb
def sync_pulses():
h_sync_left = width - left_buffer + h_front_porch
h_sync_right = h_sync_left + h_sync_width
h_sync.next = polarity
if h_sync_left <= h_count and h_count < h_sync_right:
h_sync.next = not polarity
v_sync_left = height - top_buffer + v_front_porch
v_sync_right = v_sync_left + v_sync_width
v_sync.next = polarity
if v_sync_left <= v_count and v_count < v_sync_right:
v_sync.next = not polarity
#always_comb
def blanking():
vidon.next = 0
if h_count < width - left_buffer - right_buffer and v_count < height - top_buffer - bottom_buffer:
vidon.next = 1
#always_comb
def x_y_adjust():
# x and y are only used when vidon = 1. during this time x = h_count and y = v_count
x.next = h_count[len(x.val):]
y.next = v_count[len(y.val):]
return counters, sync_pulses, blanking, x_y_adjust
width = 800
height = 600
frequency = 72
clk = Signal(bool(0))
x = Signal(intbv(0)[(width-1).bit_length():])
y = Signal(intbv(0)[(height-1).bit_length():])
h_sync = Signal(bool(0))
v_sync = Signal(bool(0))
vidon = Signal(bool(0))
vga_timer_inst = toVHDL(vga_timer, clk, x, y, h_sync, v_sync, vidon, width, height, frequency)
Any miscellaneous advice on my code is also welcome.
You may have found this out by now, but if you want convertible code, you can't use the signal qualities (min, max, number of bits, etc.) in the combinational or sequential blocks. You can use them in constant assignments outside these blocks, though. So if you put these instead of your print statements:
h_counter_max = h_count.val.max - 1
v_counter_max = v_count.val.max - 1
you can use h_counter_max and v_counter_max in your tests on line 30 and 33.
The min, max attributes can be used in the latest version.