kandi background
Explore Kits

Enzo | contains custom controls for JavaFX

 by   HanSolo Java Version: Current License: Apache-2.0

 by   HanSolo Java Version: Current License: Apache-2.0

Download this library from

kandi X-RAY | Enzo Summary

Enzo is a Java library typically used in User Interface, JavaFX applications. Enzo has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can download it from GitHub.
A repo that contains custom controls for JavaFX 8 (current version is hosted on bitbucket).
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • Enzo has a low active ecosystem.
  • It has 80 star(s) with 29 fork(s). There are 12 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 3 open issues and 6 have been closed. On average issues are closed in 0 days. There are 3 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of Enzo is current.
Enzo Support
Best in #Java
Average in #Java
Enzo Support
Best in #Java
Average in #Java

quality kandi Quality

  • Enzo has 0 bugs and 0 code smells.
Enzo Quality
Best in #Java
Average in #Java
Enzo Quality
Best in #Java
Average in #Java

securitySecurity

  • Enzo has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • Enzo code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
Enzo Security
Best in #Java
Average in #Java
Enzo Security
Best in #Java
Average in #Java

license License

  • Enzo is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
Enzo License
Best in #Java
Average in #Java
Enzo License
Best in #Java
Average in #Java

buildReuse

  • Enzo releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • Enzo saves you 18121 person hours of effort in developing the same functionality from scratch.
  • It has 35797 lines of code, 3073 functions and 171 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
Enzo Reuse
Best in #Java
Average in #Java
Enzo Reuse
Best in #Java
Average in #Java
Top functions reviewed by kandi - BETA

kandi has reviewed Enzo and discovered the below as its top functions. This is intended to give you an instant insight into Enzo implemented functionality, and help decide if they suit your requirements.

  • Gets time in time format .
    • Update the styling of the clock .
      • Draw tickmarks .
        • Draws the sections .
          • Draw the frame .
            • Initialize the menu items .
              • Update clock state .
                • Build the matrix segment .
                  • Changes the style of the frame .
                    • Updates the trend state .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      Enzo Key Features

                      A repo that contains custom controls for JavaFX 8 (Current version is hosted on bitbucket)

                      Enzo Examples and Code Snippets

                      See all related Code Snippets

                      How to create hierarchy data in JavaScript by providing dynamic groups and summing the value?

                      copy iconCopydownload iconDownload
                      function createGroup(groups, i, data, parent){
                              
                          //Take current group    
                          var group  = groups[i];
                          var nGroup = groups[i+1];
                          
                          // No more group, stop recursivity
                          if (!group) return parent;
                          
                          // Now, let's reduce by current group
                          //FIX: We need to add an empty item to force the reduce method
                          if(data.length == 1) {
                              data.push({priceEach:0});
                          }
                          
                          var root = data.reduce((prev, next) => {        
                              //First time, add prev value
                              if(parent.length == 0) {
                              
                                  var item = {};
                                  item[group] = {
                                      "Name": prev[group],
                                      "priceEach": prev.priceEach
                                  }
                                  //Next group?
                                  if(nGroup){
                                      item[group][nGroup] = createGroup(groups, i+1, [prev], []);
                                  }
                              
                                  parent.push(item);
                              }
                          
                              //Check if we need to reduce
                              for(var item of parent){
                                  if(item[group].Name == next[group]) {
                                      item[group].priceEach += next.priceEach;
                                      //Next group?
                                      if(nGroup){
                                          item[group][nGroup] = createGroup(groups, i+1, [prev, next], item[group][nGroup]);
                                      }
                                      return parent;
                                  }
                              }
                              
                              //We did not reduce, so add next as item
                              if(next[group]) {
                                  var item = {};
                                  item[group] = {
                                      "Name": next[group],
                                      "priceEach": next.priceEach
                                  }
                                  //Next group?
                                  if(nGroup){
                                      item[group][nGroup] = createGroup(groups, i+1, [next], []);
                                  }
                              
                                  parent.push(item);
                              }
                      
                              return parent;
                          });
                          
                          return root;
                      }
                      
                      createGroup(["country", "productLine", "month"], 0, data, []);
                      

                      How to display a counter formated like that YY MM DD HH

                      copy iconCopydownload iconDownload
                      String formatDuration(Duration duration) {
                        // Create some constants we'll use during the calculation
                        const int hoursPerDay = Duration.hoursPerDay;
                        const int hoursPerYear = hoursPerDay * 365;
                        const int hoursPerMonth = hoursPerDay * 30;
                        
                        // Calculate the number of years based on the number of the total
                        // hours and deduct the number of years from the total hours
                        final int years = duration.inHours ~/ hoursPerYear;
                        int remainder = duration.inHours % hoursPerYear;
                        
                        // Do the same for months and days until reach the remaning hours
                        final int months = remainder ~/ hoursPerMonth;
                        remainder %= hoursPerMonth;
                        
                        final int days = remainder ~/ hoursPerDay;
                        remainder %= hoursPerDay;
                        
                        final int hours = remainder;
                      
                        // An alternative for your `twoDigit` method: Transform the
                        // value into a string and add a zero to it if the length of
                        // the string (i.e. number of digits) is lesser than 2
                        // Finally, join all the values delimited by a space
                        return [years, months, days, hours].map((v) => "$v".padLeft(2, "0")).join(" ");
                      }
                      
                      print(formatDuration(Duration(days: 500, minutes: 1200)));
                      // Outputs 01 04 15 20
                      
                      final int years = duration.inDays ~/ 365;
                      final int months = duration.inDays ~/ 30;
                      final int days = duration.inDays;
                      final int hours = duration.inHours;
                      
                      String formatDuration(Duration duration) {
                        // Create some constants we'll use during the calculation
                        const int hoursPerDay = Duration.hoursPerDay;
                        const int hoursPerYear = hoursPerDay * 365;
                        const int hoursPerMonth = hoursPerDay * 30;
                        
                        // Calculate the number of years based on the number of the total
                        // hours and deduct the number of years from the total hours
                        final int years = duration.inHours ~/ hoursPerYear;
                        int remainder = duration.inHours % hoursPerYear;
                        
                        // Do the same for months and days until reach the remaning hours
                        final int months = remainder ~/ hoursPerMonth;
                        remainder %= hoursPerMonth;
                        
                        final int days = remainder ~/ hoursPerDay;
                        remainder %= hoursPerDay;
                        
                        final int hours = remainder;
                      
                        // An alternative for your `twoDigit` method: Transform the
                        // value into a string and add a zero to it if the length of
                        // the string (i.e. number of digits) is lesser than 2
                        // Finally, join all the values delimited by a space
                        return [years, months, days, hours].map((v) => "$v".padLeft(2, "0")).join(" ");
                      }
                      
                      print(formatDuration(Duration(days: 500, minutes: 1200)));
                      // Outputs 01 04 15 20
                      
                      final int years = duration.inDays ~/ 365;
                      final int months = duration.inDays ~/ 30;
                      final int days = duration.inDays;
                      final int hours = duration.inHours;
                      
                      String formatDuration(Duration duration) {
                        // Create some constants we'll use during the calculation
                        const int hoursPerDay = Duration.hoursPerDay;
                        const int hoursPerYear = hoursPerDay * 365;
                        const int hoursPerMonth = hoursPerDay * 30;
                        
                        // Calculate the number of years based on the number of the total
                        // hours and deduct the number of years from the total hours
                        final int years = duration.inHours ~/ hoursPerYear;
                        int remainder = duration.inHours % hoursPerYear;
                        
                        // Do the same for months and days until reach the remaning hours
                        final int months = remainder ~/ hoursPerMonth;
                        remainder %= hoursPerMonth;
                        
                        final int days = remainder ~/ hoursPerDay;
                        remainder %= hoursPerDay;
                        
                        final int hours = remainder;
                      
                        // An alternative for your `twoDigit` method: Transform the
                        // value into a string and add a zero to it if the length of
                        // the string (i.e. number of digits) is lesser than 2
                        // Finally, join all the values delimited by a space
                        return [years, months, days, hours].map((v) => "$v".padLeft(2, "0")).join(" ");
                      }
                      
                      print(formatDuration(Duration(days: 500, minutes: 1200)));
                      // Outputs 01 04 15 20
                      
                      final int years = duration.inDays ~/ 365;
                      final int months = duration.inDays ~/ 30;
                      final int days = duration.inDays;
                      final int hours = duration.inHours;
                      

                      How to get key and values using NamedTuple

                      copy iconCopydownload iconDownload
                      data = """
                      [discord]
                          [discord.filtered]
                              [[discord.filtered.swedish]]
                                  eu = "https://discordapp.com/api/webhooks/1...."
                                  asia = "https://discordapp.com/api/webhooks/2...."
                                  
                              [[discord.unfiltered.mixed]]
                                  eu = "https://discordapp.com/api/webhooks/7...."
                                  asia = "https://discordapp.com/api/webhooks/8..."   
                                  
                          [discord.unfiltered]
                              [[discord.unfiltered.swedish]]
                                  eu = "https://discordapp.com/api/webhooks/3...."
                                  asia = "https://discordapp.com/api/webhooks/4...."
                               
                              [[discord.unfiltered.mixed]]
                                  eu = "https://discordapp.com/api/webhooks/5...."
                                  asia = "https://discordapp.com/api/webhooks/6..."   
                      """
                      
                      import toml
                      
                      mapping = toml.loads(data)
                      print(mapping)
                      
                      {'discord': {'discord.filtered': {'discord.filtered.swedish': {'asia': '...', 'eu': '...'},
                                                        'discord.unfiltered.mixed': {'asia': '...', 'eu': '...'}},
                                   'discord.unfiltered': {'discord.unfiltered.mixed': {'asia': '...', 'eu': '...'},
                                                          'discord.unfiltered.swedish': {'asia': '...', 'eu': '...'}}}}
                      
                      def filter_dict(dicts, name: str, filtered: bool):
                          key_1st = "discord"
                          key_2nd = "filtered" if filtered else "unfiltered"
                          key_3rd = name
                          return dicts[key_1st]['.'.join((key_1st, key_2nd))]['.'.join((key_1st, key_2nd, key_3rd))] 
                      
                      print(filter_dict(mapping, name="swedish", filtered=True))
                      # Outputs {'eu': 'https://discordapp.com/api/webhooks/1....', 'asia': 'https://discordapp.com/api/webhooks/2....'}
                      
                      data = """
                      [discord]
                          [discord.filtered]
                              [[discord.filtered.swedish]]
                                  eu = "https://discordapp.com/api/webhooks/1...."
                                  asia = "https://discordapp.com/api/webhooks/2...."
                                  
                              [[discord.unfiltered.mixed]]
                                  eu = "https://discordapp.com/api/webhooks/7...."
                                  asia = "https://discordapp.com/api/webhooks/8..."   
                                  
                          [discord.unfiltered]
                              [[discord.unfiltered.swedish]]
                                  eu = "https://discordapp.com/api/webhooks/3...."
                                  asia = "https://discordapp.com/api/webhooks/4...."
                               
                              [[discord.unfiltered.mixed]]
                                  eu = "https://discordapp.com/api/webhooks/5...."
                                  asia = "https://discordapp.com/api/webhooks/6..."   
                      """
                      
                      import toml
                      
                      mapping = toml.loads(data)
                      print(mapping)
                      
                      {'discord': {'discord.filtered': {'discord.filtered.swedish': {'asia': '...', 'eu': '...'},
                                                        'discord.unfiltered.mixed': {'asia': '...', 'eu': '...'}},
                                   'discord.unfiltered': {'discord.unfiltered.mixed': {'asia': '...', 'eu': '...'},
                                                          'discord.unfiltered.swedish': {'asia': '...', 'eu': '...'}}}}
                      
                      def filter_dict(dicts, name: str, filtered: bool):
                          key_1st = "discord"
                          key_2nd = "filtered" if filtered else "unfiltered"
                          key_3rd = name
                          return dicts[key_1st]['.'.join((key_1st, key_2nd))]['.'.join((key_1st, key_2nd, key_3rd))] 
                      
                      print(filter_dict(mapping, name="swedish", filtered=True))
                      # Outputs {'eu': 'https://discordapp.com/api/webhooks/1....', 'asia': 'https://discordapp.com/api/webhooks/2....'}
                      
                      data = """
                      [discord]
                          [discord.filtered]
                              [[discord.filtered.swedish]]
                                  eu = "https://discordapp.com/api/webhooks/1...."
                                  asia = "https://discordapp.com/api/webhooks/2...."
                                  
                              [[discord.unfiltered.mixed]]
                                  eu = "https://discordapp.com/api/webhooks/7...."
                                  asia = "https://discordapp.com/api/webhooks/8..."   
                                  
                          [discord.unfiltered]
                              [[discord.unfiltered.swedish]]
                                  eu = "https://discordapp.com/api/webhooks/3...."
                                  asia = "https://discordapp.com/api/webhooks/4...."
                               
                              [[discord.unfiltered.mixed]]
                                  eu = "https://discordapp.com/api/webhooks/5...."
                                  asia = "https://discordapp.com/api/webhooks/6..."   
                      """
                      
                      import toml
                      
                      mapping = toml.loads(data)
                      print(mapping)
                      
                      {'discord': {'discord.filtered': {'discord.filtered.swedish': {'asia': '...', 'eu': '...'},
                                                        'discord.unfiltered.mixed': {'asia': '...', 'eu': '...'}},
                                   'discord.unfiltered': {'discord.unfiltered.mixed': {'asia': '...', 'eu': '...'},
                                                          'discord.unfiltered.swedish': {'asia': '...', 'eu': '...'}}}}
                      
                      def filter_dict(dicts, name: str, filtered: bool):
                          key_1st = "discord"
                          key_2nd = "filtered" if filtered else "unfiltered"
                          key_3rd = name
                          return dicts[key_1st]['.'.join((key_1st, key_2nd))]['.'.join((key_1st, key_2nd, key_3rd))] 
                      
                      print(filter_dict(mapping, name="swedish", filtered=True))
                      # Outputs {'eu': 'https://discordapp.com/api/webhooks/1....', 'asia': 'https://discordapp.com/api/webhooks/2....'}
                      

                      Overwrite __call__ method of third party class at runtime, while maintaining other methods

                      copy iconCopydownload iconDownload
                      class A():
                          def __call__(self, *args, **kwargs):
                              print("In A.__call__")
                      
                          def showCall(self):
                              print(self.__call__)
                      
                      class foo(A):
                          pass
                      
                      class bar(A):
                          pass
                      
                      class baz(A):
                          pass
                      
                      def my_custom_func():
                          print("In my custom func")
                      
                      f = foo()
                      f()
                      
                      b = bar()
                      b()
                      
                      f.showCall()
                      b.showCall()
                      
                      print("##setting call##")
                      f.__call__ = my_custom_func
                      print("##running f calls##")
                      f.showCall()
                      f()
                      
                      print("##running b calls##")
                      b.showCall()
                      b()
                      
                      # Create a decorator to keep the reference to the original __call__'s
                      class CustomA(A):
                          def __init__(self, obj):
                              self.obj = obj
                              
                          def __call__(self, x, y):
                              return self.obj(x, y)
                              
                          def method1(self, a, b):
                              return self.obj.method1(a, b)
                              
                      # Create a decorator that calls the original __call__
                      class MultiplyA(CustomA):
                          def __init__(self, obj):
                              super().__init__(obj)
                              
                          def __call__(self, x, y):
                              result = super().__call__(x, y)
                              return result * 10
                              
                      # Create a decorator that ignores the original __call__
                      class DivideA(CustomA):
                          def __init__(self, obj):
                              super().__init__(obj)
                              
                          def __call__(self, x, y):
                              # You can still access the original object' attributes here
                              super().method1(x, y)
                              return x / y
                      
                      foo = Foo()
                      print(foo(1, 2))
                      # Outputs 3
                      
                      foo = MultiplyA(foo)
                      print(foo(1, 2))
                      # Outputs 30
                      
                      bar = Bar()
                      print(bar(2, 3))
                      # Outputs 6
                      
                      bar = DivideA(bar)
                      print(bar(10, 5))
                      # Outputs 2.0
                      
                      # Create a decorator to keep the reference to the original __call__'s
                      class CustomA(A):
                          def __init__(self, obj):
                              self.obj = obj
                              
                          def __call__(self, x, y):
                              return self.obj(x, y)
                              
                          def method1(self, a, b):
                              return self.obj.method1(a, b)
                              
                      # Create a decorator that calls the original __call__
                      class MultiplyA(CustomA):
                          def __init__(self, obj):
                              super().__init__(obj)
                              
                          def __call__(self, x, y):
                              result = super().__call__(x, y)
                              return result * 10
                              
                      # Create a decorator that ignores the original __call__
                      class DivideA(CustomA):
                          def __init__(self, obj):
                              super().__init__(obj)
                              
                          def __call__(self, x, y):
                              # You can still access the original object' attributes here
                              super().method1(x, y)
                              return x / y
                      
                      foo = Foo()
                      print(foo(1, 2))
                      # Outputs 3
                      
                      foo = MultiplyA(foo)
                      print(foo(1, 2))
                      # Outputs 30
                      
                      bar = Bar()
                      print(bar(2, 3))
                      # Outputs 6
                      
                      bar = DivideA(bar)
                      print(bar(10, 5))
                      # Outputs 2.0
                      

                      Filter a list of tuples based on the first two elements of each tuple

                      copy iconCopydownload iconDownload
                      items = [
                       (0, 7, 'Lorenzo'),
                       (0, 16, 'Lorenzo Malburto'),
                       (3, 7, 'enzo'),
                       (8, 16, 'Malburto'),
                       (9, 13, 'albu'),
                       (24, 32, 'American'),
                       (25, 32, 'merican'),
                       (33, 50, 'singer-songwriter'),
                       (34, 50, 'inger-songwriter'),
                       (44, 47, 'wri'),
                       (44, 50, 'writer'),
                       (53, 61, 'Malburto'),
                       (54, 58, 'albu'),
                       (90, 97, 'Lorenzo'),
                       (93, 97, 'enzo')]
                      
                      # Added solely for readability
                      # If you decide to use tuples, you can replace 
                      #   - item.start with item[0]
                      #   - item.end with item[1]
                      #   - item.value with item[2]
                      import collections
                      Item = collections.namedtuple('Item', ('start', 'end', 'value'))
                      items = [Item(*value) for value in items]
                      
                      def uniquefy(items):
                          results = []
                          previous_item = None
                          
                          for current_item in items:
                              # If it's the first iteration, define the current range
                              if previous_item is None:
                                  previous_item = current_item
                                  continue
                              
                              # Detect if the current item corresponds to a new range
                              # If the previous range is [0, 5] and the current range is [7, 10]
                              # (note that 7 > 5), add the previous range to results and update
                              # the current range
                              if current_item.start > previous_item.end:
                                  results.append(previous_item)
                                  previous_item = current_item
                                  continue
                              
                              # Detect if the current item corresponds to the same range but wider
                              # If the previous range is [0, 5] and the current range is [3, 10]
                              # (note that 0 < 3 < 5 < 10), update the current range
                              if current_item.start <= previous_item.start <= previous_item.end <= current_item.end:
                                  previous_item = current_item
                          
                          # If there's still a value to be added to results
                          if previous_item is not None:
                              results.append(previous_item)
                              
                          return [item.value for item in results]
                              
                      print(uniquefy(items))
                      # Outputs ['Lorenzo Malburto', 'American', 'singer-songwriter', 'Malburto', 'Lorenzo']
                      

                      How to get dictionary of sub-object using __dict__ on main object?

                      copy iconCopydownload iconDownload
                      # Equivalent to your Engine class
                      class Foo:
                          def __init__(self, value):
                              self.v1 = value
                              
                      # Equivalent to your Battery class
                      class Bar:
                          def __init__(self, value):
                              self.v2 = value
                              
                      # Equivalent to your Wheels class
                      class Baz:
                          def __init__(self, value):
                              self.v3 = value
                          
                      # Equivalent to your Car class
                      class FBB:
                          def __init__(self):
                              self.v = 0
                              self.foo = Foo(1)
                              self.bar = Bar(2)
                              self.baz = Baz(3)
                              
                      fbb = FBB()
                      print({k: vars(v) if hasattr(v, '__dict__') else v for k, v in vars(fbb).items()})
                      # {'v': 0, 'foo': {'v1': 1}, 'bar': {'v2': 2}, 'baz': {'v3': 3}}
                      
                      class Foo:
                          def __init__(self, value):
                              self.v1 = value
                              
                      class Bar:
                          def __init__(self, value):
                              self.v2 = value
                              # Contains a reference to Baz!
                              self.baz = Baz(3)
                              
                      class Baz:
                          def __init__(self, value):
                              self.v3 = value
                          
                      class FBB:
                          def __init__(self):
                              self.v = 0
                              self.foo = Foo(1)
                              self.bar = Bar(2)
                              
                      def full_vars(obj):
                          return {k: full_vars(v) if hasattr(v, '__dict__') else v for k, v in vars(obj).items()}
                              
                      fbb = FBB()
                      print(full_vars(fbb))
                      # {'v': 0, 'foo': {'v1': 1}, 'bar': {'v2': 2, 'baz': {'v3': 3}}}
                      
                      # Equivalent to your Engine class
                      class Foo:
                          def __init__(self, value):
                              self.v1 = value
                              
                      # Equivalent to your Battery class
                      class Bar:
                          def __init__(self, value):
                              self.v2 = value
                              
                      # Equivalent to your Wheels class
                      class Baz:
                          def __init__(self, value):
                              self.v3 = value
                          
                      # Equivalent to your Car class
                      class FBB:
                          def __init__(self):
                              self.v = 0
                              self.foo = Foo(1)
                              self.bar = Bar(2)
                              self.baz = Baz(3)
                              
                      fbb = FBB()
                      print({k: vars(v) if hasattr(v, '__dict__') else v for k, v in vars(fbb).items()})
                      # {'v': 0, 'foo': {'v1': 1}, 'bar': {'v2': 2}, 'baz': {'v3': 3}}
                      
                      class Foo:
                          def __init__(self, value):
                              self.v1 = value
                              
                      class Bar:
                          def __init__(self, value):
                              self.v2 = value
                              # Contains a reference to Baz!
                              self.baz = Baz(3)
                              
                      class Baz:
                          def __init__(self, value):
                              self.v3 = value
                          
                      class FBB:
                          def __init__(self):
                              self.v = 0
                              self.foo = Foo(1)
                              self.bar = Bar(2)
                              
                      def full_vars(obj):
                          return {k: full_vars(v) if hasattr(v, '__dict__') else v for k, v in vars(obj).items()}
                              
                      fbb = FBB()
                      print(full_vars(fbb))
                      # {'v': 0, 'foo': {'v1': 1}, 'bar': {'v2': 2, 'baz': {'v3': 3}}}
                      
                      class Engine:
                          def __init__(self, vol:int):
                              self.vol = vol
                              
                      class Wheel:
                          def __init__(self, radius:int):
                              self.radius = radius
                          def __repr__(self):
                              # consider maybe using json.dump instead of str (__repr__ has to return str)
                              return str(self.__dict__)
                      
                      class Car:
                          def __init__(self, name:str, **kwargs):
                              self.name = name
                              self.parts = kwargs or dict()
                              
                          def add_part(self, part):
                              self.parts[type(part).__name__] = part
                          
                          def remove_part(self, part):
                              self.parts.pop(part.__name__, None)
                              
                      
                      x = Car("BMW")
                      x.add_part(Engine(50))
                      print(x.parts)
                      x.add_part(Wheel(35))
                      print(x.parts)
                      x.remove_part(Engine)
                      print(x.parts)
                      
                      {'Engine': <__main__.Engine object at 0x7436868c70>}
                      {'Engine': <__main__.Engine object at 0x7436868c70>, 'Wheel': {'radius': 35}}
                      {'Wheel': {'radius': 35}}
                      
                      >>> print(x.__dict__)
                      
                      {'name': 'BMW', 'parts': {'Wheel': {'radius': 35}}}
                      
                      class Engine:
                          def __init__(self, vol:int):
                              self.vol = vol
                              
                      class Wheel:
                          def __init__(self, radius:int):
                              self.radius = radius
                          def __repr__(self):
                              # consider maybe using json.dump instead of str (__repr__ has to return str)
                              return str(self.__dict__)
                      
                      class Car:
                          def __init__(self, name:str, **kwargs):
                              self.name = name
                              self.parts = kwargs or dict()
                              
                          def add_part(self, part):
                              self.parts[type(part).__name__] = part
                          
                          def remove_part(self, part):
                              self.parts.pop(part.__name__, None)
                              
                      
                      x = Car("BMW")
                      x.add_part(Engine(50))
                      print(x.parts)
                      x.add_part(Wheel(35))
                      print(x.parts)
                      x.remove_part(Engine)
                      print(x.parts)
                      
                      {'Engine': <__main__.Engine object at 0x7436868c70>}
                      {'Engine': <__main__.Engine object at 0x7436868c70>, 'Wheel': {'radius': 35}}
                      {'Wheel': {'radius': 35}}
                      
                      >>> print(x.__dict__)
                      
                      {'name': 'BMW', 'parts': {'Wheel': {'radius': 35}}}
                      
                      class Engine:
                          def __init__(self, vol:int):
                              self.vol = vol
                              
                      class Wheel:
                          def __init__(self, radius:int):
                              self.radius = radius
                          def __repr__(self):
                              # consider maybe using json.dump instead of str (__repr__ has to return str)
                              return str(self.__dict__)
                      
                      class Car:
                          def __init__(self, name:str, **kwargs):
                              self.name = name
                              self.parts = kwargs or dict()
                              
                          def add_part(self, part):
                              self.parts[type(part).__name__] = part
                          
                          def remove_part(self, part):
                              self.parts.pop(part.__name__, None)
                              
                      
                      x = Car("BMW")
                      x.add_part(Engine(50))
                      print(x.parts)
                      x.add_part(Wheel(35))
                      print(x.parts)
                      x.remove_part(Engine)
                      print(x.parts)
                      
                      {'Engine': <__main__.Engine object at 0x7436868c70>}
                      {'Engine': <__main__.Engine object at 0x7436868c70>, 'Wheel': {'radius': 35}}
                      {'Wheel': {'radius': 35}}
                      
                      >>> print(x.__dict__)
                      
                      {'name': 'BMW', 'parts': {'Wheel': {'radius': 35}}}
                      

                      'tuple' object has no attribute 'plot'

                      copy iconCopydownload iconDownload
                      fig, ax = plt.subplots()
                      ax.plot(coDF2020LA['Date_Local'],coDF2020LA['Arithmetic_Mean'])
                      ax.axvspan(date2num(datetime(2020,3,1)), date2num(datetime(2020,5,1)),color="blue", alpha=0.3)
                      

                      replace nested for-loops on multidimensional array with mclapply()

                      copy iconCopydownload iconDownload
                      fun_on_names <- function(Var1, Var2, Var3, Var4){
                       
                       a <- nchar(Var1) + nchar(Var3)
                       b <- nchar(Var2) + nchar(Var4)
                       
                       if(!is.null(a) & !is.null(b)) return(a + b)
                       else return(NA)
                       
                      }
                      
                      xy[] <- do.call(parallel::mcmapply, 
                                      c(list(FUN = fun_on_names, mc.cores = 96),
                                        expand.grid(dimnames(xy), stringsAsFactors = FALSE)))
                      
                      df <- expand.grid(dimnames(xy), stringsAsFactors = FALSE)
                      xy[] <- parallel::mcmapply(FUN = fun_on_names, 
                                                 mc.cores = 96,
                                                 df[[1]], df[[2]], df[[3]], df[[4]])
                      
                      fun_on_names <- function(Var1, Var2, Var3, Var4){
                       
                       a <- nchar(Var1) + nchar(Var3)
                       b <- nchar(Var2) + nchar(Var4)
                       
                       if(!is.null(a) & !is.null(b)) return(a + b)
                       else return(NA)
                       
                      }
                      
                      xy[] <- do.call(parallel::mcmapply, 
                                      c(list(FUN = fun_on_names, mc.cores = 96),
                                        expand.grid(dimnames(xy), stringsAsFactors = FALSE)))
                      
                      df <- expand.grid(dimnames(xy), stringsAsFactors = FALSE)
                      xy[] <- parallel::mcmapply(FUN = fun_on_names, 
                                                 mc.cores = 96,
                                                 df[[1]], df[[2]], df[[3]], df[[4]])
                      

                      _vfptr becomes null when I try to call a function

                      copy iconCopydownload iconDownload
                      o.push_back(&m); // HERE IS WHERE I PUT THE RENDERMODEL OBJECT 
                      
                      auto m = make_unique<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      auto m = make_shared<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      std::vector<std::unique_ptr<Object>> o;  // or shared_ptr if you need shared ownersheep
                      
                      o.push_back(std::move(m)); // or o.push_back(m) if shared_ptr
                      
                      o.push_back(&m); // HERE IS WHERE I PUT THE RENDERMODEL OBJECT 
                      
                      auto m = make_unique<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      auto m = make_shared<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      std::vector<std::unique_ptr<Object>> o;  // or shared_ptr if you need shared ownersheep
                      
                      o.push_back(std::move(m)); // or o.push_back(m) if shared_ptr
                      
                      o.push_back(&m); // HERE IS WHERE I PUT THE RENDERMODEL OBJECT 
                      
                      auto m = make_unique<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      auto m = make_shared<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      std::vector<std::unique_ptr<Object>> o;  // or shared_ptr if you need shared ownersheep
                      
                      o.push_back(std::move(m)); // or o.push_back(m) if shared_ptr
                      
                      o.push_back(&m); // HERE IS WHERE I PUT THE RENDERMODEL OBJECT 
                      
                      auto m = make_unique<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      auto m = make_shared<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      std::vector<std::unique_ptr<Object>> o;  // or shared_ptr if you need shared ownersheep
                      
                      o.push_back(std::move(m)); // or o.push_back(m) if shared_ptr
                      
                      o.push_back(&m); // HERE IS WHERE I PUT THE RENDERMODEL OBJECT 
                      
                      auto m = make_unique<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      auto m = make_shared<RenderModels>(Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDevice(), Armageddon::Application::GetInstance()->GetWindow()->GetWindowGraphics()->GetComptrDeviceContext())
                      
                      std::vector<std::unique_ptr<Object>> o;  // or shared_ptr if you need shared ownersheep
                      
                      o.push_back(std::move(m)); // or o.push_back(m) if shared_ptr
                      

                      TypeError: list indices must be integers or slices not str

                      copy iconCopydownload iconDownload
                      csv_file = csv.DictReader(csv_file)
                      
                      with open(input_file_path) as csv_file:
                          csv_file = csv.reader(csv_file)
                          for row in csv_file:
                      
                      with open(input_file_path) as csv_file:
                          reader = csv.reader(csv_file)
                          for row in reader:
                      
                      from io import StringIO
                      
                      scsv = '''
                      Ro Number,Date In,Rego Number,Customer Name,Vehicle Make,Vehicle Model,Job Description,Current Status,Time In,Time Out
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      654321,31/07/2020,acb321,Nate Diaz,Ferrari,Enzo,Crank but wont fire,,9:30:00 AM,4:45:00 PM
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      '''.strip()
                      
                      f = StringIO(scsv)
                      reader = csv.DictReader(f)
                      for row in reader:
                               RoNumber = row['Ro Number']
                               DateIn = row['Date In']
                               TimeIn = row['Time In']
                               TimeOut = row['Time Out']
                               RegoNumber = row['Rego Number']
                               CustomerName = row['Customer Name']
                               VehicleMake = row['Vehicle Make']
                               VehicleModel = row['Vehicle Model']
                               JobDescription = row['Job Description']
                               CurrentStatus = row['Current Status']
                               
                               print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      import tkinter as tk
                      from tkinter import *
                      import tkinter.ttk as tkrttk
                      from PIL import Image, ImageFont, ImageTk
                      import csv
                      from tkinter import filedialog
                      
                      def select_input_file(x):
                        input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
                        with open(input_file_path) as csv_file:
                          rdr = csv.DictReader(csv_file)
                          for row in rdr:
                                RoNumber = row['Ro Number']
                                DateIn = row['Date In']
                                TimeIn = row['Time In']
                                TimeOut = row['Time Out']
                                RegoNumber = row['Rego Number']
                                CustomerName = row['Customer Name']
                                VehicleMake = row['Vehicle Make']
                                VehicleModel = row['Vehicle Model']
                                JobDescription = row['Job Description']
                                CurrentStatus = row['Current Status']
                      
                                print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      widget = Button(None, text='Open CSV')
                      widget.pack()
                      widget.bind('<Button-1>', select_input_file)
                      widget.mainloop()
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      csv_file = csv.DictReader(csv_file)
                      
                      with open(input_file_path) as csv_file:
                          csv_file = csv.reader(csv_file)
                          for row in csv_file:
                      
                      with open(input_file_path) as csv_file:
                          reader = csv.reader(csv_file)
                          for row in reader:
                      
                      from io import StringIO
                      
                      scsv = '''
                      Ro Number,Date In,Rego Number,Customer Name,Vehicle Make,Vehicle Model,Job Description,Current Status,Time In,Time Out
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      654321,31/07/2020,acb321,Nate Diaz,Ferrari,Enzo,Crank but wont fire,,9:30:00 AM,4:45:00 PM
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      '''.strip()
                      
                      f = StringIO(scsv)
                      reader = csv.DictReader(f)
                      for row in reader:
                               RoNumber = row['Ro Number']
                               DateIn = row['Date In']
                               TimeIn = row['Time In']
                               TimeOut = row['Time Out']
                               RegoNumber = row['Rego Number']
                               CustomerName = row['Customer Name']
                               VehicleMake = row['Vehicle Make']
                               VehicleModel = row['Vehicle Model']
                               JobDescription = row['Job Description']
                               CurrentStatus = row['Current Status']
                               
                               print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      import tkinter as tk
                      from tkinter import *
                      import tkinter.ttk as tkrttk
                      from PIL import Image, ImageFont, ImageTk
                      import csv
                      from tkinter import filedialog
                      
                      def select_input_file(x):
                        input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
                        with open(input_file_path) as csv_file:
                          rdr = csv.DictReader(csv_file)
                          for row in rdr:
                                RoNumber = row['Ro Number']
                                DateIn = row['Date In']
                                TimeIn = row['Time In']
                                TimeOut = row['Time Out']
                                RegoNumber = row['Rego Number']
                                CustomerName = row['Customer Name']
                                VehicleMake = row['Vehicle Make']
                                VehicleModel = row['Vehicle Model']
                                JobDescription = row['Job Description']
                                CurrentStatus = row['Current Status']
                      
                                print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      widget = Button(None, text='Open CSV')
                      widget.pack()
                      widget.bind('<Button-1>', select_input_file)
                      widget.mainloop()
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      csv_file = csv.DictReader(csv_file)
                      
                      with open(input_file_path) as csv_file:
                          csv_file = csv.reader(csv_file)
                          for row in csv_file:
                      
                      with open(input_file_path) as csv_file:
                          reader = csv.reader(csv_file)
                          for row in reader:
                      
                      from io import StringIO
                      
                      scsv = '''
                      Ro Number,Date In,Rego Number,Customer Name,Vehicle Make,Vehicle Model,Job Description,Current Status,Time In,Time Out
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      654321,31/07/2020,acb321,Nate Diaz,Ferrari,Enzo,Crank but wont fire,,9:30:00 AM,4:45:00 PM
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      '''.strip()
                      
                      f = StringIO(scsv)
                      reader = csv.DictReader(f)
                      for row in reader:
                               RoNumber = row['Ro Number']
                               DateIn = row['Date In']
                               TimeIn = row['Time In']
                               TimeOut = row['Time Out']
                               RegoNumber = row['Rego Number']
                               CustomerName = row['Customer Name']
                               VehicleMake = row['Vehicle Make']
                               VehicleModel = row['Vehicle Model']
                               JobDescription = row['Job Description']
                               CurrentStatus = row['Current Status']
                               
                               print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      import tkinter as tk
                      from tkinter import *
                      import tkinter.ttk as tkrttk
                      from PIL import Image, ImageFont, ImageTk
                      import csv
                      from tkinter import filedialog
                      
                      def select_input_file(x):
                        input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
                        with open(input_file_path) as csv_file:
                          rdr = csv.DictReader(csv_file)
                          for row in rdr:
                                RoNumber = row['Ro Number']
                                DateIn = row['Date In']
                                TimeIn = row['Time In']
                                TimeOut = row['Time Out']
                                RegoNumber = row['Rego Number']
                                CustomerName = row['Customer Name']
                                VehicleMake = row['Vehicle Make']
                                VehicleModel = row['Vehicle Model']
                                JobDescription = row['Job Description']
                                CurrentStatus = row['Current Status']
                      
                                print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      widget = Button(None, text='Open CSV')
                      widget.pack()
                      widget.bind('<Button-1>', select_input_file)
                      widget.mainloop()
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      csv_file = csv.DictReader(csv_file)
                      
                      with open(input_file_path) as csv_file:
                          csv_file = csv.reader(csv_file)
                          for row in csv_file:
                      
                      with open(input_file_path) as csv_file:
                          reader = csv.reader(csv_file)
                          for row in reader:
                      
                      from io import StringIO
                      
                      scsv = '''
                      Ro Number,Date In,Rego Number,Customer Name,Vehicle Make,Vehicle Model,Job Description,Current Status,Time In,Time Out
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      654321,31/07/2020,acb321,Nate Diaz,Ferrari,Enzo,Crank but wont fire,,9:30:00 AM,4:45:00 PM
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      '''.strip()
                      
                      f = StringIO(scsv)
                      reader = csv.DictReader(f)
                      for row in reader:
                               RoNumber = row['Ro Number']
                               DateIn = row['Date In']
                               TimeIn = row['Time In']
                               TimeOut = row['Time Out']
                               RegoNumber = row['Rego Number']
                               CustomerName = row['Customer Name']
                               VehicleMake = row['Vehicle Make']
                               VehicleModel = row['Vehicle Model']
                               JobDescription = row['Job Description']
                               CurrentStatus = row['Current Status']
                               
                               print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      import tkinter as tk
                      from tkinter import *
                      import tkinter.ttk as tkrttk
                      from PIL import Image, ImageFont, ImageTk
                      import csv
                      from tkinter import filedialog
                      
                      def select_input_file(x):
                        input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
                        with open(input_file_path) as csv_file:
                          rdr = csv.DictReader(csv_file)
                          for row in rdr:
                                RoNumber = row['Ro Number']
                                DateIn = row['Date In']
                                TimeIn = row['Time In']
                                TimeOut = row['Time Out']
                                RegoNumber = row['Rego Number']
                                CustomerName = row['Customer Name']
                                VehicleMake = row['Vehicle Make']
                                VehicleModel = row['Vehicle Model']
                                JobDescription = row['Job Description']
                                CurrentStatus = row['Current Status']
                      
                                print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      widget = Button(None, text='Open CSV')
                      widget.pack()
                      widget.bind('<Button-1>', select_input_file)
                      widget.mainloop()
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      csv_file = csv.DictReader(csv_file)
                      
                      with open(input_file_path) as csv_file:
                          csv_file = csv.reader(csv_file)
                          for row in csv_file:
                      
                      with open(input_file_path) as csv_file:
                          reader = csv.reader(csv_file)
                          for row in reader:
                      
                      from io import StringIO
                      
                      scsv = '''
                      Ro Number,Date In,Rego Number,Customer Name,Vehicle Make,Vehicle Model,Job Description,Current Status,Time In,Time Out
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      654321,31/07/2020,acb321,Nate Diaz,Ferrari,Enzo,Crank but wont fire,,9:30:00 AM,4:45:00 PM
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      '''.strip()
                      
                      f = StringIO(scsv)
                      reader = csv.DictReader(f)
                      for row in reader:
                               RoNumber = row['Ro Number']
                               DateIn = row['Date In']
                               TimeIn = row['Time In']
                               TimeOut = row['Time Out']
                               RegoNumber = row['Rego Number']
                               CustomerName = row['Customer Name']
                               VehicleMake = row['Vehicle Make']
                               VehicleModel = row['Vehicle Model']
                               JobDescription = row['Job Description']
                               CurrentStatus = row['Current Status']
                               
                               print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      import tkinter as tk
                      from tkinter import *
                      import tkinter.ttk as tkrttk
                      from PIL import Image, ImageFont, ImageTk
                      import csv
                      from tkinter import filedialog
                      
                      def select_input_file(x):
                        input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
                        with open(input_file_path) as csv_file:
                          rdr = csv.DictReader(csv_file)
                          for row in rdr:
                                RoNumber = row['Ro Number']
                                DateIn = row['Date In']
                                TimeIn = row['Time In']
                                TimeOut = row['Time Out']
                                RegoNumber = row['Rego Number']
                                CustomerName = row['Customer Name']
                                VehicleMake = row['Vehicle Make']
                                VehicleModel = row['Vehicle Model']
                                JobDescription = row['Job Description']
                                CurrentStatus = row['Current Status']
                      
                                print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      widget = Button(None, text='Open CSV')
                      widget.pack()
                      widget.bind('<Button-1>', select_input_file)
                      widget.mainloop()
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      csv_file = csv.DictReader(csv_file)
                      
                      with open(input_file_path) as csv_file:
                          csv_file = csv.reader(csv_file)
                          for row in csv_file:
                      
                      with open(input_file_path) as csv_file:
                          reader = csv.reader(csv_file)
                          for row in reader:
                      
                      from io import StringIO
                      
                      scsv = '''
                      Ro Number,Date In,Rego Number,Customer Name,Vehicle Make,Vehicle Model,Job Description,Current Status,Time In,Time Out
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      654321,31/07/2020,acb321,Nate Diaz,Ferrari,Enzo,Crank but wont fire,,9:30:00 AM,4:45:00 PM
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      '''.strip()
                      
                      f = StringIO(scsv)
                      reader = csv.DictReader(f)
                      for row in reader:
                               RoNumber = row['Ro Number']
                               DateIn = row['Date In']
                               TimeIn = row['Time In']
                               TimeOut = row['Time Out']
                               RegoNumber = row['Rego Number']
                               CustomerName = row['Customer Name']
                               VehicleMake = row['Vehicle Make']
                               VehicleModel = row['Vehicle Model']
                               JobDescription = row['Job Description']
                               CurrentStatus = row['Current Status']
                               
                               print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      import tkinter as tk
                      from tkinter import *
                      import tkinter.ttk as tkrttk
                      from PIL import Image, ImageFont, ImageTk
                      import csv
                      from tkinter import filedialog
                      
                      def select_input_file(x):
                        input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
                        with open(input_file_path) as csv_file:
                          rdr = csv.DictReader(csv_file)
                          for row in rdr:
                                RoNumber = row['Ro Number']
                                DateIn = row['Date In']
                                TimeIn = row['Time In']
                                TimeOut = row['Time Out']
                                RegoNumber = row['Rego Number']
                                CustomerName = row['Customer Name']
                                VehicleMake = row['Vehicle Make']
                                VehicleModel = row['Vehicle Model']
                                JobDescription = row['Job Description']
                                CurrentStatus = row['Current Status']
                      
                                print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      widget = Button(None, text='Open CSV')
                      widget.pack()
                      widget.bind('<Button-1>', select_input_file)
                      widget.mainloop()
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      csv_file = csv.DictReader(csv_file)
                      
                      with open(input_file_path) as csv_file:
                          csv_file = csv.reader(csv_file)
                          for row in csv_file:
                      
                      with open(input_file_path) as csv_file:
                          reader = csv.reader(csv_file)
                          for row in reader:
                      
                      from io import StringIO
                      
                      scsv = '''
                      Ro Number,Date In,Rego Number,Customer Name,Vehicle Make,Vehicle Model,Job Description,Current Status,Time In,Time Out
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      654321,31/07/2020,acb321,Nate Diaz,Ferrari,Enzo,Crank but wont fire,,9:30:00 AM,4:45:00 PM
                      123456,6/07/2020,abc123,Conor McGregor,Hyundai ,i30,"15,000 Km Service",,8:00:00 AM,4:00:00 PM
                      '''.strip()
                      
                      f = StringIO(scsv)
                      reader = csv.DictReader(f)
                      for row in reader:
                               RoNumber = row['Ro Number']
                               DateIn = row['Date In']
                               TimeIn = row['Time In']
                               TimeOut = row['Time Out']
                               RegoNumber = row['Rego Number']
                               CustomerName = row['Customer Name']
                               VehicleMake = row['Vehicle Make']
                               VehicleModel = row['Vehicle Model']
                               JobDescription = row['Job Description']
                               CurrentStatus = row['Current Status']
                               
                               print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      
                      import tkinter as tk
                      from tkinter import *
                      import tkinter.ttk as tkrttk
                      from PIL import Image, ImageFont, ImageTk
                      import csv
                      from tkinter import filedialog
                      
                      def select_input_file(x):
                        input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
                        with open(input_file_path) as csv_file:
                          rdr = csv.DictReader(csv_file)
                          for row in rdr:
                                RoNumber = row['Ro Number']
                                DateIn = row['Date In']
                                TimeIn = row['Time In']
                                TimeOut = row['Time Out']
                                RegoNumber = row['Rego Number']
                                CustomerName = row['Customer Name']
                                VehicleMake = row['Vehicle Make']
                                VehicleModel = row['Vehicle Model']
                                JobDescription = row['Job Description']
                                CurrentStatus = row['Current Status']
                      
                                print(RoNumber,DateIn,TimeIn,TimeOut)
                      
                      widget = Button(None, text='Open CSV')
                      widget.pack()
                      widget.bind('<Button-1>', select_input_file)
                      widget.mainloop()
                      
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      654321 31/07/2020 9:30:00 AM 4:45:00 PM
                      123456 6/07/2020 8:00:00 AM 4:00:00 PM
                      

                      See all related Code Snippets

                      Community Discussions

                      Trending Discussions on Enzo
                      • How to create hierarchy data in JavaScript by providing dynamic groups and summing the value?
                      • How to display a counter formated like that YY MM DD HH
                      • How to get key and values using NamedTuple
                      • Overwrite __call__ method of third party class at runtime, while maintaining other methods
                      • Filter a list of tuples based on the first two elements of each tuple
                      • How to get dictionary of sub-object using __dict__ on main object?
                      • 'tuple' object has no attribute 'plot'
                      • JAVA - Insertion Sort Method from ArrayList&lt;String&gt; partially works but doesn't sort the whole list correctly
                      • replace nested for-loops on multidimensional array with mclapply()
                      • Hardware errors on Memory with a large simulation on 128 cores
                      Trending Discussions on Enzo

                      QUESTION

                      How to create hierarchy data in JavaScript by providing dynamic groups and summing the value?

                      Asked 2021-Oct-09 at 11:43

                      I want to create a dynamic hierarchy based on my groups and rollup sum to top level, also if I am providing a large amount of data browser is getting hang.

                      I have the below data:

                       var data = [
                         {
                            "country":"Spain",
                            "orderNumber":10394,
                            "year":2018,
                            "countrycode":"es",
                            "quantityOrdered":30,
                            "priceEach":60.28,
                            "productName":"1950's Chicago Surface Lines Streetcar",
                            "productLine":"Trains",
                            "sortkey":3,
                            "productCode":"S32_3207",
                            "month":"March",
                            "extendedPrice":1808.4,
                            "orderDate":"2018-03-15 00:00:00"
                         },
                         {
                            "country":"France",
                            "orderNumber":10395,
                            "year":2018,
                            "countrycode":"fr",
                            "quantityOrdered":32,
                            "priceEach":105.33,
                            "productName":"1972 Alfa Romeo GTA",
                            "productLine":"Classic Cars",
                            "sortkey":3,
                            "productCode":"S10_4757",
                            "month":"March",
                            "extendedPrice":3370.56,
                            "orderDate":"2018-03-17 00:00:00"
                         },
                         {
                            "country":"France",
                            "orderNumber":10395,
                            "year":2018,
                            "countrycode":"fr",
                            "quantityOrdered":33,
                            "priceEach":69.12,
                            "productName":"2001 Ferrari Enzo",
                            "productLine":"Classic Cars",
                            "sortkey":3,
                            "productCode":"S12_1108",
                            "month":"March",
                            "extendedPrice":2280.96,
                            "orderDate":"2018-03-17 00:00:00"
                         },
                         {
                            "country":"France",
                            "orderNumber":10395,
                            "year":2018,
                            "countrycode":"fr",
                            "quantityOrdered":46,
                            "priceEach":123.76,
                            "productName":"Diamond T620 Semi-Skirted Tanker",
                            "productLine":"Trucks and Buses",
                            "sortkey":3,
                            "productCode":"S50_1392",
                            "month":"March",
                            "extendedPrice":5692.96,
                            "orderDate":"2018-03-17 00:00:00"
                         },
                         {
                            "country":"France",
                            "orderNumber":10395,
                            "year":2018,
                            "countrycode":"fr",
                            "quantityOrdered":45,
                            "priceEach":199.49,
                            "productName":"1962 City of Detroit Streetcar",
                            "productLine":"Trains",
                            "sortkey":3,
                            "productCode":"S50_1514",
                            "month":"March",
                            "extendedPrice":8977.05,
                            "orderDate":"2018-03-17 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":33,
                            "priceEach":185.13,
                            "productName":"1969 Ford Falcon",
                            "productLine":"Classic Cars",
                            "sortkey":3,
                            "productCode":"S12_3891",
                            "month":"March",
                            "extendedPrice":6109.29,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":33,
                            "priceEach":159.81,
                            "productName":"1903 Ford Model A",
                            "productLine":"Vintage Cars",
                            "sortkey":3,
                            "productCode":"S18_3140",
                            "month":"March",
                            "extendedPrice":5273.73,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":24,
                            "priceEach":89.75,
                            "productName":"Collectable Wooden Train",
                            "productLine":"Trains",
                            "sortkey":3,
                            "productCode":"S18_3259",
                            "month":"March",
                            "extendedPrice":2154,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":45,
                            "priceEach":105.32,
                            "productName":"1904 Buick Runabout",
                            "productLine":"Vintage Cars",
                            "sortkey":3,
                            "productCode":"S18_4522",
                            "month":"March",
                            "extendedPrice":4739.4,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":49,
                            "priceEach":116.75,
                            "productName":"18th century schooner",
                            "productLine":"Ships",
                            "sortkey":3,
                            "productCode":"S24_2011",
                            "month":"March",
                            "extendedPrice":5720.75,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":27,
                            "priceEach":83.2,
                            "productName":"1912 Ford Model T Delivery Wagon",
                            "productLine":"Vintage Cars",
                            "sortkey":3,
                            "productCode":"S24_3151",
                            "month":"March",
                            "extendedPrice":2246.4,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":37,
                            "priceEach":90.57,
                            "productName":"1940 Ford Delivery Sedan",
                            "productLine":"Vintage Cars",
                            "sortkey":3,
                            "productCode":"S24_3816",
                            "month":"March",
                            "extendedPrice":3351.09,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"USA",
                            "orderNumber":10396,
                            "year":2018,
                            "countrycode":"us",
                            "quantityOrdered":39,
                            "priceEach":66.67,
                            "productName":"The Schooner Bluenose",
                            "productLine":"Ships",
                            "sortkey":3,
                            "productCode":"S700_1138",
                            "month":"March",
                            "extendedPrice":2600.13,
                            "orderDate":"2018-03-23 00:00:00"
                         },
                         {
                            "country":"France",
                            "orderNumber":10397,
                            "year":2018,
                            "countrycode":"fr",
                            "quantityOrdered":32,
                            "priceEach":80.55,
                            "productName":"The Mayflower",
                            "productLine":"Ships",
                            "sortkey":3,
                            "productCode":"S700_1938",
                            "month":"March",
                            "extendedPrice":2577.6,
                            "orderDate":"2018-03-28 00:00:00"
                         }
                      ]
                      

                      I have created below function but its not working properly

                      var groups = ['country', 'productLine', 'month']; // this can be dynamic 
                      var sum = ['priceEach']; // this can be dynamic 
                      
                      function createGroup (groups, data, sum, childNode) {
                          let [primaryGroup, ...rest] = groups;
                      
                          let groupedData = data.reduce((acc, current) => {
                          let chunk = {
                              'Name': current[primaryGroup],
                              [primaryGroup]: current[primaryGroup],
                              [sum]: data.filter(item => item[primaryGroup] === current[primaryGroup])
                              .map(el => el[sum])
                              .reduce((total, current) => total + current),
                             ...(rest.length > 0 ? {[groups[childNode]]: createGroup(rest, data, sum,childNode+1 )} : {})
                          }
                      
                          acc.push(chunk)
                          return acc
                        }, [])
                          .reduce((acc, current) => {
                              const x = acc.find(item => item[primaryGroup] === current[primaryGroup])
                              return !x ? acc.concat([current]) : acc
                          }, [])
                      
                        return groupedData;
                      }
                      
                      const tree = createGroup(groups,data,sum, 1);
                      

                      Required below sample result (I haven't included other country but I need all)

                      [
                         {
                            "country":[
                               {
                                  "Name":"Spain",
                                  "priceEach":60.28,
                                  "productline":[
                                     {
                                        "Name":"Trains",
                                        "priceEach":60.28,
                                        "month":[
                                           {
                                              "Name":"March",
                                              "priceEach":60.28
                                           }
                                        ]
                                     }
                                  ]
                               }
                            ]
                         },
                         {
                            "country":[
                               {
                                  "Name":"France",
                                  "priceEach":578.25,
                                  "productline":[
                                     {
                                        "Name":"Classic Cars",
                                        "priceEach":174.45,
                                        "month":[
                                           {
                                              "Name":"March",
                                              "priceEach":174.45
                                           }
                                        ]
                                     },
                                     {
                                        "Name":"Trucks and Buses",
                                        "priceEach":123.76,
                                        "month":[
                                           {
                                              "Name":"March",
                                              "priceEach":123.76
                                           }
                                        ]
                                     },
                                     {
                                        "Name":"Trains",
                                        "priceEach":199.49,
                                        "month":[
                                           {
                                              "Name":"April",
                                              "priceEach":199.49
                                           }
                                        ]
                                     },
                                     {
                                        "Name":"Ships",
                                        "priceEach":80.55,
                                        "month":[
                                           {
                                              "Name":"June",
                                              "priceEach":80.55
                                           }
                                        ]
                                     }
                                  ]
                               }
                            ]
                         }
                      ]
                      

                      ANSWER

                      Answered 2021-Oct-09 at 11:43

                      Well, it is probably hangs because of O(n log n) (you iterate the same data over and over).

                      Note: priceEach is static in this solution, but you can redesign the recursive function

                      function createGroup(groups, i, data, parent){
                              
                          //Take current group    
                          var group  = groups[i];
                          var nGroup = groups[i+1];
                          
                          // No more group, stop recursivity
                          if (!group) return parent;
                          
                          // Now, let's reduce by current group
                          //FIX: We need to add an empty item to force the reduce method
                          if(data.length == 1) {
                              data.push({priceEach:0});
                          }
                          
                          var root = data.reduce((prev, next) => {        
                              //First time, add prev value
                              if(parent.length == 0) {
                              
                                  var item = {};
                                  item[group] = {
                                      "Name": prev[group],
                                      "priceEach": prev.priceEach
                                  }
                                  //Next group?
                                  if(nGroup){
                                      item[group][nGroup] = createGroup(groups, i+1, [prev], []);
                                  }
                              
                                  parent.push(item);
                              }
                          
                              //Check if we need to reduce
                              for(var item of parent){
                                  if(item[group].Name == next[group]) {
                                      item[group].priceEach += next.priceEach;
                                      //Next group?
                                      if(nGroup){
                                          item[group][nGroup] = createGroup(groups, i+1, [prev, next], item[group][nGroup]);
                                      }
                                      return parent;
                                  }
                              }
                              
                              //We did not reduce, so add next as item
                              if(next[group]) {
                                  var item = {};
                                  item[group] = {
                                      "Name": next[group],
                                      "priceEach": next.priceEach
                                  }
                                  //Next group?
                                  if(nGroup){
                                      item[group][nGroup] = createGroup(groups, i+1, [next], []);
                                  }
                              
                                  parent.push(item);
                              }
                      
                              return parent;
                          });
                          
                          return root;
                      }
                      
                      createGroup(["country", "productLine", "month"], 0, data, []);
                      

                      JSFiddle

                      If country, productLine, month are static, you can run the classic way

                      Source https://stackoverflow.com/questions/69502219

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install Enzo

                      You can download it from GitHub.
                      You can use Enzo like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Enzo component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Explore Related Topics

                      Share this Page

                      share link
                      Consider Popular Java Libraries
                      Try Top Libraries by HanSolo
                      Compare Java Libraries with Highest Support
                      Compare Java Libraries with Highest Quality
                      Compare Java Libraries with Highest Security
                      Compare Java Libraries with Permissive License
                      Compare Java Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.