Org-gantt adds a week when calculating from effort estimate - elisp

Org-gantt seems to fulfill my gantt-chart creation needs. It works
on an org-mode file
with tasks of duration measured in less than days
on effort estimates - or should do...
It seems to have a bug though making it add a week when calculating the end or start date for a task with an effort estimate and either a schedule or a deadline. Hense running the example from section 3.2.1
in the manual the resulting end date for Weld Frame is the 27th and not the 20th and the start date for Paint Frame is the 13th and not the 20th and so on:
#+BEGIN: org-gantt-chart :id "effort-src" :use-id-subheadlines t :start-date "2015-05-15" :end-date "2015-05-31"
\begin{ganttchart}[time slot format=isodate, vgrid={*3{black},*4{dashed}}]{2015-05-15}{2015-05-31}
\gantttitlecalendar{year, month=name, day}\\
\ganttgroup[group left shift=0.0, group right shift=-0.0, name=uniqueid1]{Frame}{2015-05-19}{2015-05-21}\\
\ganttbar[bar left shift=0.0, bar right shift=-0.0, name=uniqueid2]{Weld Frame}{2015-05-19}{2015-05-27}\\
\ganttbar[bar left shift=0.0, bar right shift=-0.0, name=uniqueid3]{Paint Frame}{2015-05-13}{2015-05-21}\\
\ganttgroup[group left shift=0.0, group right shift=-0.0, name=uniqueid4]{Other Parts}{2015-05-22}{2015-05-27}\\
\ganttbar[bar left shift=0.0, bar right shift=-0.625, name=uniqueid5]{Assemble Parts}{2015-05-22}{2015-06-02}\\
\ganttbar[bar left shift=0.375, bar right shift=-0.0, name=uniqueid6]{Fix Parts to Frame}{2015-05-15}{2015-05-27}\\
\end{ganttchart}
#+END
Using only deadlines and schedules it works fine, but when using effort estimates it does not and even when
changing the hours-per-day
changing the work-free-days
using effort estimates of several weeks
using an effort estimate of 0d
it still gives an end date with 7 days added when using SCHEDULED or a start date with seven days withdrawn when using DEADLINE in the org-file. Therefore it has to be when the effort is added or withdrawn the SCHEDULED or the DEADLINE date perhaps in the org-gantt-calculate-ds-from-effort function in the org-gantt.el file.
I am still a newbie in lisp programming and therefore I hope someone else can find where and what the problem is or what else to do (and perhaps make a suggestion at the repository to the author).
Thanks,
Chris

Related

Date logic puzzle: calculating UTC equivalent to yesterday local time at 8 AM

Banging my head on this simple date logic problem:
I know the user's time zone offset relative to UTC.
My server is in UTC. It knows the time now.
How do I calculate UTC equivalent of 'yesterday local time at 8am'?
IN JS, I tried to do it this, but it seems to not quite work.
var yesterday_am=moment(moment(new Date()).subtract(24,'hour')).format('YYYY-MM-DD'); // same local time previous day;
// when is 8am local time in utc?
var am=8 - (user.tz_offset/60);
if (am<0) { yesterday_am=moment(yesterday_am).subtract(Math.abs(am), 'hour')};
if (am>0) { yesterday_am=moment(yesterday_am).add(am, 'hour')};
For example, if UTC is 2016-01-10 0235 and local time is -7 hours, it would output 2016-1-09 1500 (8am local).
The logic you are trying to perform is impossible. Without knowing the user's actual time zone, you cannot know the UTC equivalent of 'yesterday at 8 am' local time. Daylight saving time transitions may make the offset yesterday different than the offset today. See the time zone tag wiki, particularly the Time Zone != Offset section for more information.
If you do know the user's time zone, then you can perform this calculation using the moment timezone add-on library for Moment.js. The code would be as follows:
moment().tz('America/Los_Angeles').subtract(1, 'day')
.set({hours:8, minutes:0, seconds:0, milliseconds:0}).utc()
Breaking this down so it makes sense, we are doing the following things:
moment() //get the current time
.tz('America/Los_Angeles') //put the moment in the Los Angeles time zone
//the Los Angeles time zone is one of several that are UTC-7 right now
.subtract(1, 'day') //go to yesterday
.set({hours:8, minutes:0, seconds:0, milliseconds:0}) //set the time to exactly 8 am
.utc() //convert back to UTC
Do not add 8 hours to the start of the day. This will be 9 AM if the clocks 'sprang forward' that day, and 7 am if they 'fell back'.
It sounds like your code is running in Node on the server. If it is running in the browser, then the browser knows the user's time zone rules, and you could use the following code to get the time at 8 am yesterday:
moment().subtract(1, 'day').set({hours:8, minutes:0, seconds:0, milliseconds:0}).utc()
This code does not require the moment timezone add on because the browser knows the time zone rules for the user's local time.
If you need to get the user's time zone, you have a few options. The most reliable is to use a timezone picker built into a map to let the user choose. There are a few of these floating around the internet.
If you do not want to do that, you can use the moment.tz.guess() function to have moment timezone make an educated guess about the user's time zone using some heuristics. This function is good, but due to limitations of the browser it is impossible to make it 100% accurate.
For a whole bunch of information about handling date and time and time zones in JavaScript, you can try this talk I did at JavaScript MN a few months ago.
In addition, you might like this really excellent Pluralsight course by Matt Johnson.
This code is not DST aware (in case if you've not already figure out based on the comments below). Thank you Maggie. Please refer to complete answer from Maggie.
You can do something like this
var localTime = moment.utc("2016-06-19").utcOffset('-07:00');
var utcAt8PrevDay = moment(localTime).subtract(1,'days').startOf('day').add(8, 'hour').utc();

Is a FSM in a state possible?

I was wondering whether or not it's possible to implement the following.
What do I want to do?. Imagine the Big Ben's melody. I want to play a fourth of the melody every quarter of an hour. I want a FSM which has the following states:
Whole hour (so xx:00) = (input = 01)
Quarter past/ Quarter to (so xx:15 / xx:45) = (input = 10)
Half past (so xx:30) = (input = 11).
(xx = dont care)
For each state, i have another FSM. This FSM will make sure the music will play correctly.
If(state = whole hour)
{
switch music_state
case A
{ play 1 sec, next_music_state = F}
case and so on ......
Does this work? Can I make a FSM which has the different states of an hour, and for each state have another FSM?
If something is unclear, let me know, and I will try to clarify it. I know this part is not that hard, but I am still wondering whether or not this implementation will work. I hope, and also think, it will, though I want to be certain of it.
Thanks a lot in advance!
Meta-state machines with both an "inner state" and an "outer state" are certainly possible. I have done something similar for a while but it was only last week that the penny dropped and I finally wrote a state machine with two separate states. In a single process SM, it worked like a dream.
The "inner state machine" runs just like a normal state machine but in its last state, you test the meta-state or outer state, to determine which part of the outer sequence to despatch to next.
You could make single FSM to keep it simple...
The default state will be IDLE: This will check for the time (whole hour, quarters or half past), if one of them happens, you'll just run proper states like:
MUSIC_FOR_WHOLE_HOUR, MUSIC_FOR_HALF_PAST ...
Those states will run their different chain of states that will play their music and will return back to the IDLE state to wait for next proper time to play again.

System Date Changes to correct time but year 8113

Every couple of days (2 times a week) a desktop (Win. 7) starts up with my date-time updated. The time, date & month is correct but in year 8113. This makes several programs like Word/Excel working inappropriate & crashing.
BIOS/CMOS battery has been replaced, several antivirus programs had scanned & find find any virusses. No malware or suspicious software is installed.
Does it sounds familiar to someone ?
I would appreciate any help or advice.
Thanks !
I know you would probably like an answer that tackles the origin of your problem. Unfortunately I don't see where this could come from.
Instead, I wanted to suggest that you check your time-synchronization. Windows can sync with time servers and does so in a predefined interval.
You could try to change the time-server and to change the interval.
The time-server can be changed like this:
http://mintywhite.com/windows-7/7maintenance/windows-seven-7-sync-system-clock-with-internet-time-how-to/
The interval has to be changed by altering a registry key, namely
\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time
\TimeProviders\NtpClient
(It is in seconds, so 86400 is the value for an interval of 1 day!).
Maybe it's not a fix of the originating problem, but frequent updates of your system time should reduce the resulting problems.

I am totally confused this is an online class I have no clue how to do this homework can anyone tutor me

Question is:
Write pseudocode for a program that
calculates the service charge of a
customer owes for writing a bad check.
The program accepts a customer's name,
the date the check was written (year,
month and day), the current date
(year, month and day), and the amount
of the check in dollars and cents. The
program continues until an eof value
is encountered.
The service charge is $20 plus 2
percent of the amount of the check,
plus $5 for every month that has
passed since the check was written. A
check is one month late as soon as a
new month starts-so a bad check
written on September 30 is one month
overdue on October 1.
A program is generally a series of steps. Can you break down the problem into a series of steps necessary to calculate your answer?
Hints:
Every time the month changes, you owe another $5. Thus, "day" is irrelevant.
Next year at the same month, 12 months are passed. The previous month, the number of elapsed months is 12 - 1.
"2% more than" is equivalent to * 1.02
"Continues until EOF is reached" sounds like a loop.
Try to edit your question and make an honest attempt - no-one will solve your homework for you, but we will help you solve it.
In my humble experience, this kind of confusion is caused by trying to solve the problem and write the code at the same time.
Try solving the problem first.
Get a sheet of paper and draw a flowchart which shows the steps and decisions.
e.g. the last box might be:
EOF: Y = Stop, N = go back to "Read next line"
Pick 3 test examples e.g.
In the current month
In the last year
Greater than a year
Work these examples through your flowchart and check that the result is correct. If not, amend the flowchart and rework the test examples.
When you are happy, "translate" the flowchart into English and you will have working pseudo code.
Load the file
Read and store check_date_month in a variable
Read and store current_date_month in a variable
Read and store check_amount in a variable
Service_charge = 20 + 0.02*(check_amount) + [(current_month - check_date_month) + current_date_year - check_date_year]*5
Read customer's name and show to the user something like:
"Customer's Name"
Service charge: "$"Service_charge
The days in this case are not relevant because the charge increases every time the month changes, so, in the case we are in October and the check was done in September (10-9 = 1) we have to pay $5 more, but maybe we could be in different years, for example 2010 and 2009, that means that between October and September there are now (1 + 12 = 13) months, so now you have to pay $65. I expect this will help you to understand step 5.

UI for capturing a timespan or duration

What's a good web-based UI for capturing a time duration from the user.
Lets say that we want to capture a time duration in minutes.
But would like to present it such that the user can enter in hours and\or minutes.
Just use 2 textboxes for hrs\min?
Or a single textbox and let them type in "1hr 31min" or "91 min" ?
Or is there something better?
If you have two text boxes labelled hours and minutes then you need to deal with case where the user types into both of them.
3 into h and 35 into m => pretty clear. 3 hours 35 mins
nothing into h and 95 into m => 1 hour 35 mins (probably update the display to show that)
but what about
2 into h and then 95 into m => does that mean 3 h 35 or 1 hour 35
I've used too many annoying UIs where changing a field zaps other entries to be confident that I can devise an unastonishing set of behaviours.
Hence I would go for a single box into which we can type 3h or 1h 35m or 95m and have a separate read-only display of the interpretation.
There seems to be an opportunity for a nice widget to allow a mouse driven entry, in the same way as a calendar widget allows date entry. A little clock with dragable hands?
Thanks for all the feedback.
What I finally ended up doing was, having a single textbox that shows the time duration in the format "xxhrs yymin"
The user can edit it and when focus moves away from the textbox, it recalculates the duration and reformats the text into the canonical form.
The parser to interpret the text entered is fairly liberal.
It's a set of regular expressions to match any number followed by 'h' or 'm' or 'd' to represent hours, minutes and days.
If it doesn't find any 'unit' with a number in front of it, it assumes you have typed in a pure number as minutes and will interpret it as such.
So if the user types:
"1.5h", it will reformat to "1hr 30min" upon leaving the textbox.
"90 min" will also be reformatted as "1hr 30min"
The parser only looks at the first character following the number, which means you can enter "1 day, 7 hours and 19 minutes" and it will recognize it correctly.
Of course, it would also recognize "2 holes and 19 mice" as "2hrs and 19min".
I think I can live with that.
Just let them type the numbers only in a pre defined time format.
Place 2 textboxes for hour and minute without the hr or min.
Also you have to define whether it is a 24 hour system or 12 hour.
Well, separate hours and minutes fields is the safest but slower to use than a single field. You can default the hours to 0 if you don’t expect many durations over 1 hour.
Maybe it depends on your population, but I expect users will be able to handle hours and minutes in the same text box if you provide a prompt, such as “Time duration (hrs:min):”
With that prompt, accept any initial unbroken string of numbers as the hours and any subsequent unbroken string of numbers as minutes, so that all of the following input are treated as equivalent.
2:30
02:30
02:30:05
2.30 (or maybe not: while great for keypad entry, but you may want to make an exception for the decimal point to allow the user to enter fractional hours, such as 2.75 for 2 hrs 45 min.)
2 30
2 hrs 30 min
2 hours, 30 minutes
2jaQp 30!!!!
I see no reason to require that the minutes be less than 60. The user should also be able to express the time as:
:150
When the focus leaves the field, auto-correct whatever the users enter to the specified (hrs:min) format to feedback the interpretation you made.
If all you need for your purpose is a rough approximation of time (or your users are only estimating anyway), then consider option buttons or a dropdown list with ranges of duration (e.g., 0 to 5 minutes, 5 to 15 minutes, 15 min to 1 hour, Over an hour.). Or if there are definite bounds on the durations and the intervals are functionally linear, you can use a labeled slider.
Whatever input format or control you use, it should be compatible with the source of information. Where do users get this duration? What units, format, intervals, and degree of precision are used there? How do users think and talk about the time among themselves?
I think there should be no client side correction for the minutes greater than 60 as somebody suggested. It would only be confusing and generate unnecessary problems.
User entered the data so he should understand what he typed and there is no need to correct him.
I would leave these fields as filled by user. On the server side I would just calculate total minutes as:
$total_minutes = 60 * $_POST['hours'] + $_POST['minutes'];
I was just thinking about this and realized one familiar UI for this sort of thing is a microwave oven. For iPhone-like uses, a keypad may be better than the rolling scroller thing I often see.
In my case I think I'm going to go with a text field for "number" and a selectbox for "unit" (years, months, weeks, days, hours).
Sliders (jqueryui, html5) could be an option too, depending on what kind of range you're talking about.

Resources