domino logo
Tech Ecosystem
Get started with Python
Step 0: Orient yourself to DominoStep 1: Create a projectStep 2: Configure your projectStep 3: Start a workspaceStep 4: Get your files and dataStep 5: Develop your modelStep 6: Clean up WorkspacesStep 7: Deploy your model
Get started with R
Step 0: Orient yourself to Domino (R Tutorial)Step 1: Create a projectStep 2: Configure your projectStep 3: Start a workspaceStep 4: Get your files and dataStep 5: Develop your modelStep 6: Clean up WorkspacesStep 7: Deploy your model
Get Started with MATLAB
Step 1: Orient yourself to DominoStep 2: Create a Domino ProjectStep 3: Configure Your Domino ProjectStep 4: Start a MATLAB WorkspaceStep 5: Fetch and Save Your DataStep 6: Develop Your ModelStep 7: Clean Up Your Workspace
Step 8: Deploy Your Model
Scheduled JobsLaunchers
Step 9: Working with Domino Datasets
Domino Reference
Notifications
On-Demand Open MPI
Configure MPI PrerequisitesFile Sync MPI ClustersValidate MPI VersionWork with your ClusterManage Dependencies
Projects
Projects OverviewProjects PortfolioReference ProjectsProject Goals in Domino 4+
Git Integration
Git Repositories in DominoGit-based Projects with CodeSyncWorking from a Commit ID in Git
Jira Integration in DominoUpload Files to Domino using your BrowserFork and Merge ProjectsSearchSharing and CollaborationCommentsDomino Service FilesystemComparing File RevisionsRevert Projects and Files
Advanced Project Settings
Project DependenciesProject TagsRename a ProjectSet up your Project to Ignore FilesUpload files larger than 550MBExporting Files as a Python or R PackageTransfer Project Ownership
Domino Runs
JobsDiagnostic Statistics with dominostats.jsonNotificationsResultsRun Comparison
Advanced Options for Domino Runs
Run StatesDomino Environment VariablesEnvironment Variables for Secure Credential StorageUse Apache Airflow with Domino
Scheduled Jobs
Domino Workspaces
WorkspacesUse Git in Your WorkspaceRecreate A Workspace From A Previous CommitUse Visual Studio Code in Domino WorkspacesPersist RStudio PreferencesAccess Multiple Hosted Applications in one Workspace Session
Spark on Domino
On-Demand Spark
On-Demand Spark OverviewValidated Spark VersionConfigure PrerequisitesWork with your ClusterManage DependenciesWork with Data
External Hadoop and Spark
Hadoop and Spark OverviewConnecting to a Cloudera CDH5 cluster from DominoConnecting to a Hortonworks cluster from DominoConnect to a MapR cluster from DominoConnect to an Amazon EMR cluster from DominoRunning Local Spark on a Domino ExecutorUsing PySpark in Jupyter WorkspacesKerberos Authentication
On-Demand Ray
On-Demand Ray OverviewValidated Ray VersionConfigure PrerequisitesWork with your ClusterManage DependenciesWork with Data
On-Demand Dask
On-Demand Dask OverviewValidated Dask VersionConfigure PrerequisitesWork with Your ClusterManage DependenciesWork with Data
Customize the Domino Software Environment
Environment ManagementDomino Standard EnvironmentsInstall Packages and DependenciesAdd Workspace IDEsAdding Jupyter KernelsAutomatic Adaptation of Custom Images
Partner Environments for Domino
Use MATLAB as a WorkspaceUse Stata as a WorkspaceUse SAS as a Workspace
Advanced Options for Domino Software Environment
Publish in Domino with Custom ImagesInstall Custom Packages in Domino with Git IntegrationAdd Custom DNS Servers to Your Domino EnvironmentConfigure a Compute Environment to User Private Cran/Conda/PyPi MirrorsUse TensorBoard in Jupyter Workspaces
Publish your Work
Publish a Model API
Model Publishing OverviewModel Invocation SettingsModel Access and CollaborationModel Deployment ConfigurationPromote Projects to ProductionExport Model ImageExport to NVIDIA Fleet Command
Publish a Web Application
App Publishing OverviewGet Started with DashGet Started with ShinyGet Started with FlaskContent Security Policies for Web Apps
Advanced Web Application Settings in Domino
App Scaling and PerformanceHost HTML Pages from DominoHow to Get the Domino Username of an App Viewer
Launchers
Launchers OverviewAdvanced Launcher Editor
Assets Portfolio Overview
Model Monitoring and Remediation
Monitor WorkflowsData Drift and Quality Monitoring
Set up Monitoring for Model APIs
Set up Prediction CaptureSet up Drift DetectionSet up Model Quality MonitoringSet up NotificationsSet Scheduled ChecksSet up Cohort Analysis
Set up Model Monitor
Connect a Data SourceRegister a ModelSet up Drift DetectionSet up Model Quality MonitoringSet up Cohort AnalysisSet up NotificationsSet Scheduled Checks
Use Monitoring
Access the Monitor DashboardAnalyze Data DriftAnalyze Model QualityExclude Features from Scheduled Checks
Remediation
Cohort Analysis
Review the Cohort Analysis
Remediate a Model API
Monitor Settings
API TokenHealth DashboardNotification ChannelsTest Defaults
Monitoring Config JSON
Supported Binning Methods
Model Monitoring APIsTroubleshoot the Model Monitor
Connect to your Data
Data in Domino
Datasets OverviewProject FilesDatasets Best Practices
Connect to Data Sources
External Data VolumesDomino Data Sources
Connect to External Data
Connect Domino to DataRobotConnect to Azure Data Lake StorageConnect to BigQuery from DominoConnect to Google Cloud Storage from DominoConnect to IBM DB2 from DominoConnect to IBM Netezza from DominoConnect to Impala from DominoConnect to MSSQL from DominoConnect to MySQL from DominoConnect to Okera from DominoConnect to Oracle Database from DominoConnect to PostgreSQL from DominoConnect to Redshift from DominoConnect to S3 from DominoConnect to Snowflake from DominoConnect to Teradata from Domino
Work with Data Best Practices
Work with Big Data in DominoWork with Lots of FilesMove Data Over a Network
Advanced User Configuration Settings
User API KeysDomino TokenOrganizations Overview
Use the Domino Command Line Interface (CLI)
Install the Domino Command Line (CLI)Domino CLI ReferenceDownload Files with the CLIForce-Restore a Local ProjectMove a Project Between Domino DeploymentsUse the Domino CLI Behind a Proxy
Browser Support
Get Help with Domino
Additional ResourcesGet Domino VersionContact Domino Technical SupportSupport Bundles
domino logo
About Domino
Domino Data LabKnowledge BaseData Science BlogCommunityTraining
User Guide
>
Get Started with MATLAB
>
Step 8: Deploy Your Model
>
Scheduled Jobs

Scheduled Jobs

Use the Scheduled Jobs feature in Domino to run a script regularly.

You can create reports in MATLAB using the publish() function and the robust MATLAB Report Generator. To simplify things, in this tutorial, you will use the publish() function, which uses a MATLAB m file as a document template.

Imagine that you receive data daily about Berlin’s weather. You want to generate a scheduled email visualizing this data, as well as the forecasted number of hot days in the next 365 days.

To do that, create the following files:

  • An m. file, based on your Live Script, that will:

    • Load Berlin weather data from a URL.

    • Prepare the data.

    • Generate predictions using the model you create with the data.

    • Call the publish() function.

  • An m. file that will be your report template that shows:

    • A weather prediction plot.

    • The number of predicted hot days.

Step 8.1: Publish the weather prediction report

  1. Go to Workspaces and click Open Last Workspace.

  2. Go to New > Script to create a new file.

  3. Click Save > Save As to name it predictWeatherReport.m.

  4. Copy and paste the following code to your file. This code initializes a struct to hold the results, defines a hot day temperature threshold (in degrees Celsius), downloads the current data for Berlin weather, and saves it to the workspace. It will read the downloaded file into a table format.

    %% Initial setup
    result = struct;
    hotDayThreshold = 30;
    %% Download data file
    urlString = "https://www.ncei.noaa.gov/data/global-historical-climatology-network-daily/access/GME00121150.csv";
    if ~isfolder("data")
      mkdir('data');
    end
    savedFileName = sprintf("%s%s%s", "data", filesep, "berlin.csv");
    websave(savedFileName, urlString);
    
    %% Read the downloaded file
    opts = detectImportOptions(savedFileName);
    opts.SelectedVariableNames = {'DATE', 'PRCP', 'TMIN', 'TMAX'};
    opts = setvartype(opts, {'DATE','PRCP','TMIN','TMAX'},{'datetime','double', 'double', 'double'});
    stationWeatherTbl = readtable(savedFileName, opts);
  5. To prepare the data, copy and paste the following code that will start with data from the year 1999, adjust the temperature data to full degrees, and complete missing data. If there are less than 1000 rows of data, the data will stop processing.

    %%
    [stationWeatherTbl.year, stationWeatherTbl.month, stationWeatherTbl.day] = ymd(stationWeatherTbl.DATE);
    % MATLAB strength
    stationWeatherTbl = stationWeatherTbl(stationWeatherTbl.year > 1999 & stationWeatherTbl.year < max(stationWeatherTbl.year), :);
    stationWeatherTbl.TMAX = stationWeatherTbl.TMAX/10;
    stationWeatherTbl.TMIN = stationWeatherTbl.TMIN/10;
    stationWeatherTbl = fillmissing(stationWeatherTbl, 'linear');
    
    %% check if there is enough data for prediction
    dataRows = size(stationWeatherTbl, 1);
    if dataRows < 1000
        disp('Not enough data for prediction');
        result.error = 'Not enough data for prediction';
        return;
    end
  6. Copy and paste the following code which will load the model that you created previously and save it into a .mat file. Then, it will create the table to use as input with the updated data that was read from the URL previously.

    %% Check if we have a model for this weather station
    modelFileName = sprintf("%s%s%s%s", "models", filesep, "weatherStationId", ".mat");
    
    % make sure we have a folder for the models
    if ~isfolder('models')
      mkdir('models')
    end
    
    if ~isfile(modelFileName)
      disp('Training model for weather station...')
      cv = cvpartition(stationWeatherTbl.year, 'Holdout', 0.3);
      dataTrain = stationWeatherTbl(cv.training, :);
    
      [weatherModel, validationRMSE] = trainRegressionModel(dataTrain);
    
      % display prediction precision
      doneMessage = sprintf('%s%d', "Done. Model RMSE:", validationRMSE);
      disp(doneMessage);
      save(modelFileName, 'weatherModel');
    else
     load(modelFileName, 'weatherModel');
    end
    %% Create table for future date prediction
    todayDate = datetime('today');
    daysIntoFuture = 365;
    endDate = todayDate + days(daysIntoFuture);
    predictedMaxTemps = table('Size', [daysIntoFuture+1 7], 'VariableTypes',  {'datetime', 'double', 'double', 'double', 'double', 'double', 'double'}, 'VariableNames', stationWeatherTbl.Properties.VariableNames);
    x=1;
    
    for i=todayDate:endDate
      % get the average perception and minimum temps on this date
      [y, m, d] = ymd(i);
    
      minTemps = stationWeatherTbl.TMIN(stationWeatherTbl.month == m & stationWeatherTbl.day == d);
      prcps = stationWeatherTbl.PRCP(stationWeatherTbl.month == m & stationWeatherTbl.day == d);
    
      curMinTemp = NaN;
      [historicalRowCount z] = size(minTemps);
      randomRow = randi([1 historicalRowCount]);
      curMinTemp = minTemps(randomRow);
      predictedMaxTemps.TMIN(x) = curMinTemp;
      randomRow = randi([1 historicalRowCount]);
      predictedMaxTemps.PRCP(x) = prcps(randomRow);
      predictedMaxTemps.DATE(x) = i;
      predictedMaxTemps.year(x) = y;
      predictedMaxTemps.month(x) = m;
      predictedMaxTemps.day(x) = d;
      predictedMaxTemps.TMAX(x) = 0;
      x = x+1;
    end
  7. Copy and paste the following code that will run the model and load the result struct with the prediction.

    %%
    yFit = weatherModel.predictFcn(predictedMaxTemps);
    predResult = table(predictedMaxTemps.DATE, yFit, 'VariableNames', {'Date', 'Predicted TMAX'});
    result.predictedTemps = predResult;
    hotWeatherDaysIdx = predResult(predResult.("Predicted TMAX") > hotDayThreshold, :);
    result.hotDayCountPrediction = height(hotWeatherDaysIdx);
  8. Copy and paste the following code to share the prediction result with the template in the .mst file. You must include this because the publish() function runs in isolation from the workspace. To ensure the data file has a unique name for each run of this script, this code uses the Domino environment variable for the run number.

    %% save data to file
    dominoRunId = getenv('DOMINO_RUN_NUMBER');
    outputFileName = sprintf('%s%s%s', 'results', filesep, 'predictData_', string(dominoRunId));
    save(outputFileName, 'result');
  9. Copy and paste the following code to call the publish() function. The report will be published to a subfolder of the results/ folder, along with the number of the current run in the filename.

    %% Publish the report
    
    % options for the report
    pub_options.format = 'pdf';
    
    % hide the report code
    pub_options.showCode = false;
    pub_options.outputDir = sprintf('%s%s%s', 'results', filesep, dominoRunId);
    doc = publish('predictWeatherReportTemplate.m', pub_options);
  10. Click Save.

Step 7.2: Create the report template

  1. To create the report template, create a script named predictWeatherReportTemplate.m. Copy and paste the following code to load the data. This tutorial uses the following format for the filename when loading the data: results/predictData_<Domino Run Number>. The data is stored in a variable called result.

    dominoRunId = getenv('DOMINO_RUN_NUMBER');
    inputFileName = sprintf('%s%s%s', 'results', filesep, 'predictData_', string(dominoRunId));
    load(inputFileName, 'result');
  2. Copy and paste the following code to add a title to the template. In this MATLAB template, comments will be rendered as markup. For more information, see MATLAB’s documentation about markup comments for publishing.

    %% Predicted Weather
  3. Copy and paste the following to add the plot with the data that you loaded previously and show the hot day predictions as output.

    predResult = result.predictedTemps;
    
    plot(predResult.Date, predResult.("Predicted TMAX"));
    titleText = "Weather forecast for the next 365 days (\circC)";
    title(titleText);
    ylabel ('Forecasted Daily High Temperature')
    
    %%
    countPredictionText = sprintf("%s%d%s", "There will be ", ...
        result.hotDayCountPrediction, " hot days in the next 365 days");
    
    disp(countPredictionText);
  4. Click Save.

  5. Click File Changes in the navigation bar. Then, click Sync All Changes to save and commit your changes.

  6. To test the predictWeatherReport.m file, type the following in the Command Window to call the file and press Enter:

    predictWeatherReport

    The following graph shows:

    job executed

    A new folder and new file are created in the results/ folder.

    current folder

  7. Save and sync your changes.

  8. Stop your MATLAB session. Click the Domino icon and then, in the navigation pane, click Scheduled Jobs.

  9. Click + New Scheduled Job.

    1. Type a name for the job and type predictWeatherReport.m as the file to run for this job.

    2. Select a hardware tier.

    3. Confirm that your environment is the same as the one in which you developed your model.

    4. Click Next.

      create scheduled job wizard

  10. On the Attach Compute Cluster page, select none and click Next

  11. Schedule the job to run every weekday. Leave the Run sequentially option checked. Click Next.

  12. Type the email addresses for those to notify when the job is complete. Click Create.

You have scheduled a job that will use your MATLAB code to generate a report. You can also go to the Jobs page to run the job on an ad-hoc basis.

To learn more about how to customize the resulting email, see Custom Notifications.

Domino Data LabKnowledge BaseData Science BlogCommunityTraining
Copyright © 2022 Domino Data Lab. All rights reserved.