Old 03-21-2020, 06:03 AM   #1
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default DEADLINE function wanted. (solved)

Hi
DEADLINE function wanted.
-----------------------------------------------------------------
-----------------------------------------------
***********Deadline works.**************
You have to add the value listed above when entering.

Thank you very much lbo and solger
-----------------------------------------------------
----------------------------------------------------

For example, the input would be "24 days".
Now the script should subtract one day every day.

Thank you

here you can download the script
https://www.dropbox.com/sh/mkk741yvo...F7DTTTfOa?dl=0




This is a section of the text file that is read in at startup.


Last edited by Dragonetti; 03-27-2020 at 06:26 AM.
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 02:35 AM   #2
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 4,160
Default

I hadn't had time to look at the code itself, but in theory a possible solution could look like this:
  1. Calculate and/or save the date of the deadline (either only internally in the text file when entering a deadline. Or in an additional 'deadline date' column) -> see Options 1 and 2 below
  2. Calculate the difference between the deadline date and and the current system date
-----------------------------

Let's say the system date today is 10.03.2020
  • Option 1: Entering a deadline of 10 (days) into your current 'deadline (days)' column. Which automatically calculates & saves the 20.03.2020 as deadline date (10.03.2020 + 10 days) into the text file
  • Option 2: Entering the date 20.03.2020 directly into a separate 'deadline date' column and calculating the 'deadline (days)' column value automatically
Code:
Option 2

DEADLINE DATE | DEADLINE (DAYS)
-----------------------------
20.03.2020    |      10 
04.04.2020    |      20 
...

The values 10 and 20 are automatically calculated and set in the
'deadline (days)' column when adding a date in the 'deadline date' column
In both cases: now you can calculate the difference between the saved deadline date (20.03.2020) and the current system date (os.date) for updating the 'deadline (days)' column values


As example:

If the current system date is 13.03.2020:
Quote:
deadline (days) = difference between deadline date (20.03.2020) minus system date (13.03.2020) <- in this case 7 days
If the current system date is 18.03.2020:
Quote:
deadline (days) = difference between deadline date (20.03.2020) minus system date (18.03.2020) <- in this case 2 days

--------------------

As additional note: if all deadlines are always in days, you might also consider to just enter the value into the column (without the 'days' part):

Code:
DEADLINE (days)
----------------
    24
    67
    23
...

Hope this info is helpful.
__________________
ReaLauncher

Last edited by solger; 03-26-2020 at 03:06 AM.
solger is offline   Reply With Quote
Old 03-26-2020, 04:21 AM   #3
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Thank you very much
I have to deal with it
It can take some time

Dragonetti
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 07:31 AM   #4
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Which would be the easiest method?

Since the input to the Project Manager is a string, a simple example should look like this.


deadline = {"60","70","23"}


how should the function be programmed so that the strings are reduced by one every day?
the strings first have to be converted into numbers...

Thanks
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 08:31 AM   #5
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

maybe you can use this here

"Lua provides automatic conversions between numbers and strings at run time.
Any numeric operation applied to a string tries to convert the string to a number:"

Code:
    t = {"60","70","23"}
    print(t[1]-1,t[2]-1,t[3]-1)
output
59 69 22

Last edited by Dragonetti; 03-26-2020 at 08:39 AM.
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 11:56 AM   #6
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 4,160
Default

Although you could subtract 1 like this ...
Code:
t = {"60","70","23"}

for i=1, #t do
  reaper.ShowConsoleMsg(tostring(t[i]-1) .. "\n")
end
... you'll still need some kind of reference point (like a creation- or end-date of the deadline entry) in order to calculate when the day counter should be updated.

Here are two quick code examples:


In this example, 3 days are added to the current system date today (26.03.2020).
The resulting deadlineTimestamp (29.03.2020) is the date value which needs to be stored - for instance, inside the text file as additional parameter

Code:
local aDay = (60 * 60 * 24)
local d = {"3"}

local today = os.time()
local deadlineTimestamp = os.date('%d.%m.%Y', today + (aDay * d[1]))

reaper.ShowConsoleMsg(tostring(deadlineTimestamp) .. "\n")

In this example, let's say the deadlineTimestamp is the one which was stored in and loaded from the text file.
The resulting daysLeft (04) is the new value for the 'Days' column - calculated from the difference between the deadlineTimestamp (30.03.2020) and today (26.03.2020).
Code:
local deadlineTimestamp = '30.03.2020'

local function dateToTime(s)
  local xDay, xMonth, xYear = s:match("(%d+)%.(%d+)%.(%d+)")
  return os.time({year = xYear, month = xMonth, day = xDay, hour = 0, min = 0, sec = 0})
end

local today = os.time()
local deadlineDate = dateToTime(deadlineTimestamp)

local daysLeft = os.date('%d', deadlineDate - today)
reaper.ShowConsoleMsg(tostring(daysLeft) .. "\n")
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 03-26-2020, 12:07 PM   #7
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Wow
That's great.
Entering the date is of course the best option.
Maybe I can integrate it all, but I don't think I can do it alone.
I had also tried out here
Thanks solger


Code:
--deadlineinput 12
local inputday = tonumber (os.date ("%j"))
local inputplusdeadline = 12 + inputday  -- should be saved in the table
local deadline = inputplusdeadline - tonumber (os.date ("%j"))  -- should be displayed

print(deadline)
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 12:49 PM   #8
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 4,160
Default

Quote:
Originally Posted by Dragonetti View Post
Entering the date is of course the best option.
Yeah, entering the date directly would be Option 2 mentioned in post #2.

--------------

The two examples in post #6 are a possible solution for Option 1:


When entering a day value into the column (first code example):
  1. Calculate the deadlineTimestamp (by adding the days (d={3} in the example to today)
  2. Store the deadlineTimestamp in the text file (as additional table parameter or instead of the 'deadline_val' one)

When loading the ProjectManager (second code example)
  1. Get the deadlineTimestamp (stored in the first example) from the text file
  2. Calculate the difference between today and the deadlineTimestamp -> daysLeft
  3. Update the 'Deadline' column with the new daysLeft value
__________________
ReaLauncher

Last edited by solger; 03-26-2020 at 01:08 PM.
solger is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.