• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Dynamic travel time

Scheduled Pinned Locked Moved Development
12 Posts 5 Posters 9.7k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    mochman Module Developer
    last edited by Oct 13, 2016, 4:25 PM

    There are a couple ways I can think of. The easiest one, that wouldn’t require recoding the traffic module would be to have 2 config.js files. One with the destination of town, and the other, work. You could set up a small bash script to switch the files and restart the mirror. You could then put that script in your crontab that runs it at the beginning of the weekend and then at the beginning of the week.

    A more lengthy way would be to have your traffic module take an array of origins/destinations/weekdays and then use it’s internal programming to display the correct commute.

    Another lengthy way would be to have the traffic module use a notificationReceived() with the payload being a origin/destination and then you creating another module that passes that info at a certain date/time.

    I’m sure there are may other ways this can be done, but those are the ones that come to mind.

    D 1 Reply Last reply Oct 13, 2016, 4:35 PM Reply Quote 0
    • D Offline
      darrene @mochman
      last edited by darrene Oct 13, 2016, 4:35 PM Oct 13, 2016, 4:35 PM

      Thanks for the suggestions @mochman - I didn’t even think about a crontab and restart approach - it’s a sledgehammer but would get the job done whilst I figure out how to implement one of the other options (or plead for someone to do it) :)

      The separate co-ordinator module approach using a payload notification feels like a really good solution - that could be fed the results of the calendar refresh, generate the destination payload and push it to the traffic module - in effect, negating the need for the traffic module updateinterval.

      1 Reply Last reply Reply Quote 0
      • Y Offline
        yawns Moderator
        last edited by Oct 13, 2016, 4:35 PM

        Maybe you can use the scheduler module, add your map module two times with different locations and schedule for workdays and weekend

        D 1 Reply Last reply Oct 13, 2016, 4:37 PM Reply Quote 0
        • D Offline
          darrene @yawns
          last edited by Oct 13, 2016, 4:37 PM

          Ooo! Good thinking @yawns - that’d possibly reduce a bunch of coding down to a bit of tweaking. I’ll investigate this option first. Thank you.

          1 Reply Last reply Reply Quote 0
          • M Offline
            MichMich Admin
            last edited by Oct 13, 2016, 6:39 PM

            For what it’s worth: I’ll be working on a change to the default calendar module this week to broadcast the events to other modules, including any location data. This way any module that want’s to show data based on the calendar can use the calendar data.

            Keep an eye on the forum about any announcements. And check out the develop branch for new features like this.

            D 1 Reply Last reply Oct 13, 2016, 7:13 PM Reply Quote 2
            • D Offline
              darrene @MichMich
              last edited by darrene Oct 13, 2016, 7:14 PM Oct 13, 2016, 7:13 PM

              Fabulous! Thanks for the heads-up @MichMich - it’s the rate of development of your mirror by everyone, that makes it so awesome.

              I’ll stay tuned to the announcements

              M 1 Reply Last reply Oct 14, 2016, 2:13 PM Reply Quote 0
              • M Offline
                MichMich Admin @darrene
                last edited by Oct 14, 2016, 2:13 PM

                @darrene It’s available in the develop branch now. Happy coding!

                D 1 Reply Last reply Oct 14, 2016, 2:51 PM Reply Quote 0
                • D Offline
                  darrene @MichMich
                  last edited by darrene Oct 14, 2016, 2:52 PM Oct 14, 2016, 2:51 PM

                  Woo! Excellent stuff. Thank you @MichMich - I’ll give it a test-drive over the weekend and feed anything constructive back

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    darrene
                    last edited by darrene Oct 15, 2016, 8:24 AM Oct 15, 2016, 8:24 AM

                    So having realised the simplest approach to a week/weekend commute display would simply be to code the date information into MM-Traffic’s MMM-Traffic.js file, I’ve added the following logic to the getParams function;

                    getParams: function() {
                    var params = '?';
                    

                    -> var d = new Date();
                    -> var n = d.getDay();

                        params += 'mode=' + this.config.mode;
                        params += '&origin=' + this.config.origin;
                    

                    -> if (n < 6) {params += ‘&destination=’ + “Cheltenham”;}
                    -> else {params += ‘&destination=’ + “Gloucester”;}

                        params += '&key=' + this.config.api_key;
                        params += '&traffic_model=' + this.config.traffic_model;
                        params += '&language=' + this.config.language;
                        return params;
                    },
                    

                    Which works like a dream :) My first bit of javascript. I’m so excited!

                    I’d like to round it off by adjusting the
                    ‘current commute is’
                    and
                    'origin to destination displays to be along the lines of ‘Work Commute’/‘Town Commute’ and ‘Home to Work’/‘Home to town’ but I’m struggling to find how to inject the logic.

                    I can see the current commute is in the defaults and symbols section. Ideally I want to change the defaults section.

                    The other is in the //routename section, but again I can’t work out how to make the alteration.

                    1 Reply Last reply Reply Quote 1
                    • D Offline
                      darrene
                      last edited by Oct 15, 2016, 8:27 PM

                      Solved! I don’t think my code-hacking is going to win any awards for elegance but it works - I get a different message and journey time depending on whether it’s the week or the weekend! :)

                      D 1 Reply Last reply Feb 9, 2017, 6:54 AM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        6/12
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy