Page 1 of 1

How can I automate periodic calculations?

PostPosted: 22 Jan 2014, 08:13
by selmar
Hello, how can I automate periodic execution of a network, or any method generally?

..like executing a method every monday, or every month, or every quarter?

thanks. Selina

Windows Job Sheduler

PostPosted: 25 Jan 2014, 15:09
by finaquant
General information about, and possible options for job sheduling on a windows operating system:
How to setup-up Job scheduling with .NET framework?

It is quite easy to configure a periodic task with Windows Sheduler, as explained here:
http://windows.microsoft.com/en-gb/wind ... =windows-7

First, create an exe file that will be executed periodically. You can configure the periodicity with Job Sheduler, as explained below.

Starting Job Sheduler on Windows:
START > Control Panel > System and Security > Administrative Tools > Shedule tasks

Select periodicity, like monthly:
Image

Select months and days:
Image

Select: Start Program
Image

Browse and select the executable file:
Image


And that's it!

Fore safety reasons (against possible errors), you can configure the Sheduler such that a task is triggered on several days in a month. If an error occurs in the first execution, this error can be recorded to a database. In the subsequent executions, the calculation method is executed only if it wasn't completed with success before within the same period.

Following example C# code shows how a simple table can automatically be inserted into a database together with the instance information (hour and minute) at recurring intervals:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. // define meta data
  2. using FinaquantCalcs;
  3. //...
  4.  
  5. MetaData md = MetaData.CreateEmptyMetaData();
  6. MetaData.AddNewField(md, "product", FieldType.TextAttribute);
  7. MetaData.AddNewField(md, "hour", FieldType.IntegerAttribute);
  8. MetaData.AddNewField(md, "minute", FieldType.IntegerAttribute);
  9. MetaData.AddNewField(md, "price", FieldType.KeyFigure);
  10.  
  11. // create simple table
  12. var PriceTblFields = TableFields.CreateEmptyTableFields(md);
  13. TableFields.AddNewField(PriceTblFields, "product");
  14. TableFields.AddNewField(PriceTblFields, "price");
  15.  
  16. MatrixTable PriceTbl = MatrixTable.CreateTableWithElements_A(PriceTblFields,
  17.     "car", 250.0,
  18.     "bus", 500.0,
  19.     "cycle", 50.0
  20.     );
  21.  
  22. // define row field structure for table instance
  23. var RowFields = TextVector.CreateVectorWithElements("hour", "minute");
  24. var InstanceTblFields = TableFields.CreateTableFields(RowFields, md);
  25.  
  26. // get time
  27. DateTime t = DateTime.Now;
  28. int Second = t.Second;
  29. int Minute = t.Minute;
  30. int Hour = t.Hour;
  31.  
  32. int daynum = DateFunctions.DateToNumber(t);
  33. int Month = DateFunctions.Month(daynum);
  34. int Quarter = DateFunctions.Quarter(daynum);
  35. int Year = DateFunctions.Year(daynum);
  36.  
  37. Console.WriteLine(Month + " - " + Quarter + " - " + Year);
  38. // System.Threading.Thread.Sleep(3000);
  39.  
  40. // connect to db, replace the connection string below with your own
  41. string ConnStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\finaquant\Documents\Visual Studio 2010\Finaquant Analytics\FinaquantCalcsStarterR103\FinaquantCalcsStarter\Databases\finaquantdb.mdf;Integrated Security=True;User Instance=True";
  42. string DBprovider = "System.Data.SqlClient";
  43. DataStore dstore = new DataStore(DBprovider);
  44.  
  45. try
  46. {
  47.     dstore.OpenConnection(ConnStr);
  48.  
  49.     // instance information for table
  50.     TableRow trow1 = TableRow.CreateTableRowWithElements(InstanceTblFields,
  51.         Hour, Minute);
  52.  
  53.     // write table into database
  54.     dstore.WriteTableInstance(PriceTbl * (100 + Minute), "pricetbl", trow1);
  55. }
  56. catch (Exception ex)
  57. {
  58.     Console.WriteLine(ex.Message);
  59. }
  60. finally
  61. {
  62.     dstore.CloseConnection();
  63. }
GeSHi ©

Re: How can I automate periodic calculations?

PostPosted: 29 Jan 2014, 22:17
by selmar
thanks a lot. May I ask another: How can I use table functions in optimization problems?

Selina

Optimization

PostPosted: 01 Feb 2014, 17:38
by finaquant
Optimization is an important issue. Could you please start a new thread for this question?