• 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.

MMM-MyCommute

Scheduled Pinned Locked Moved Transport
286 Posts 80 Posters 512.3k Views 77 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.
  • T Offline
    tidus5 @j.e.f.f
    last edited by May 30, 2017, 8:24 AM

    @j.e.f.f Perfect!!!

    thanks :-)

    1 Reply Last reply Reply Quote 0
    • J Offline
      jon11a @j.e.f.f
      last edited by jon11a May 30, 2017, 11:02 AM May 30, 2017, 11:01 AM

      Hi @j.e.f.f
      Just wanted to say, thanks so much for spending your time building this module! I have just finished my MagicMirror build and this module is by far the best and most used. I love how much I’m able to customise it to thanks to your hard work.

      Now, I wondered if it was easy to add the following… My commute is always over an hour, would it be possible to format the commute time to show 1h 30 min rather than 90 min for example? It would still show just ‘min’ if under an hour (20 min for example).

      If it’s not all that easy and you’d rather not alter the code, then that’s fine, I may have a bash at editing the code on my Pi myself.

      Thanks again!

      J 1 Reply Last reply May 30, 2017, 11:30 AM Reply Quote 0
      • J Offline
        j.e.f.f Project Sponsor Module Developer @jon11a
        last edited by May 30, 2017, 11:30 AM

        @jon11a It’s certainly possible. But it takes up considerably more space to render “1h 30 min” than it does to render “90 min”. The space that the travel time uses takes away from the space used for the text to its left. That is why I chose to render it that way. Even an extremely long commute of over 2 hours would only take up an extra 8 pixels or so. By doing it this way, it should be more or less the same width for everyone, with less chance of truncating the label.

        If you want to change this yourself, it’s a fairly trivial change to the formatTime function in MMM-MyCommute.js. Google returns the travel time in the number of seconds. I’ve just done a simple division by 60 to get the number of minutes. You can just do a little more math and re-jig the formatting as you’d like.

        Happy to hear that you like the module!

        -Jeff

        J 1 Reply Last reply May 30, 2017, 11:35 AM Reply Quote 0
        • J Offline
          jon11a @j.e.f.f
          last edited by May 30, 2017, 11:35 AM

          @j.e.f.f Thanks for your quick response Jeff. I thought that might be the reason behind your decision to just use mins. It does make sense to me.

          I think I will have a go at changing mine, will be a good little challenge for me as I’m learning more and more programming skills!

          Thanks again and I look forward to see what you come up with next ;)

          J 1 Reply Last reply May 30, 2017, 11:49 AM Reply Quote 0
          • J Offline
            j.e.f.f Project Sponsor Module Developer @jon11a
            last edited by j.e.f.f May 30, 2017, 11:50 AM May 30, 2017, 11:49 AM

            @jon11a Fair warning: this module was also the result of me wanting to change a thing or two to suit my own needs ;). Before I knew I had something completely new! It shares little resemblance with the module I originally forked from mrx-work-traffic.

            Have fun. I can’t wait to see how it evolves!

            -Jeff

            J 1 Reply Last reply May 30, 2017, 1:39 PM Reply Quote 0
            • J Offline
              jon11a @j.e.f.f
              last edited by jon11a May 30, 2017, 1:52 PM May 30, 2017, 1:39 PM

              @j.e.f.f
              Managed to do it and pretty pleased with myself :)

              Here’s what it looks like:

              0_1496151228319_commute.png

              I had to edit the css file to move the destination-label slightly as you mentioned:

              margin-right: 70px;
              

              I edited your formatTime function to format the time in hours and minutes or just minutes if it’s less than an hour in total.
              Below is the code for that function with my bits added, I am sure it could be better but I think I did ok!

              formatTime: function(time, timeInTraffic) {
              
                  var timeEl = document.createElement("span");
                  timeEl.classList.add("travel-time");
                  if (timeInTraffic != null) {
                    var minutes = Math.floor(Number(timeInTraffic) /60);
                    var h = Math.floor(minutes /60);
                    var m = Math.floor(minutes %60);
                    if (h == 0) {
                      timeEl.innerHTML = m + " min";
                    } else {
                      timeEl.innerHTML = h + "h " + m + " min";
                    }
                    var variance = timeInTraffic / time;
                    if (this.config.colorCodeTravelTime) {
                      if (variance > this.config.poorTimeThreshold) {
                        timeEl.classList.add("status-poor");
                      } else if (variance > this.config.moderateTimeThreshold) {
                        timeEl.classList.add("status-moderate");
                      } else {
                        timeEl.classList.add("status-good");
                      }
                    }
                  } else {
                    var minutes = Math.floor(Number(time) /60);
                    var h = Math.floor(minutes /60);
                    var m = Math.floor(minutes %60);
                    if (h == 0) {
                      timeEl.innerHTML = m + " min";
                    } else {
                      timeEl.innerHTML = h + "h " + m + " min";
                    }
                    timeEl.classList.add("status-good");
                  }
              

              Thanks for your help Jeff, learned some more programming skills too so I’m happy! :)

              1 Reply Last reply Reply Quote 2
              • J Offline
                joela85
                last edited by joela85 Jun 2, 2017, 6:41 AM Jun 2, 2017, 6:40 AM

                startTime & endTime query.

                I’ve tried setting these times up for the morning time before going to work and after testing it hides itself but it never re-appeared this morning?
                Has anyone else had this issue?

                module: 'MMM-MyCommute',
                  position: 'bottom_right',
                  config: {
                    showHeader: true,
                    headerText: 'Traffic',
                    apikey: 'API_KEY_FROM_GOOGLE',
                    origin: 'My Address',
                    startTime: '06:00',
                    endTime: '09:00',
                    destinations: [
                                   etc...
                

                It would also be good if you could set it to run on Mon-Fri as well.
                If not possible I could use the MMM-Scheduler to do this instead, it’s just a bit tidier in this module.

                J 1 Reply Last reply Jun 2, 2017, 12:58 PM Reply Quote 0
                • B Offline
                  Blackmirror
                  last edited by Jun 2, 2017, 7:29 AM

                  This module is great, but it was nicer, to take starttime and endtime for the different destinations.
                  So, I will go to work in the morning, soIneed this only between 5.00 and 6.00 o’clock and if I will go to the salsa party I need this only in the evening.

                  J 1 Reply Last reply Jun 4, 2017, 12:55 PM Reply Quote 0
                  • J Offline
                    j.e.f.f Project Sponsor Module Developer @joela85
                    last edited by Jun 2, 2017, 12:58 PM

                    @joela85 I just did a quick test on my laptop by changing the clock to mover forward a day at a time, and I had the module disappear and reappear consistently. I’ve set my config to startTime: '06:00' and endTime: '09:00' and I’ll let it run overnight to see if I can recreate your issue.

                    I also like the Mon-Fri idea, as well as the individual time windows per destination. Will work on them over the next few days.

                    1 Reply Last reply Reply Quote 1
                    • J Offline
                      j.e.f.f Project Sponsor Module Developer @Blackmirror
                      last edited by Jun 4, 2017, 12:55 PM

                      @Blackmirror I ran a test overnight and my module came back on when it should have. But I did realize there is a fundamental problem with how I’ve architected the data pull. Are you using two instances of this module? If so I’m thinking that may be causing problems and possibly yours. I’m going to write an update soon, and I’ll have you try again.

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 6
                      • 28
                      • 29
                      • 4 / 29
                      4 / 29
                      • First post
                        38/286
                        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