def make_google_motion_chart(self, directory):
     filename = "FGGoogleMotionChart.html"
     filepath = directory + "/" + filename
     Utility.ensure_dir(filepath)
     test = GoogleMotionChart()
     output = test.display(self.users, self.from_date)
     f = open(filepath, "w")
     f.write(output)
     f.close()
     print filepath + " created"
 def make_index_html (self, output_dir, title):
     page_template = """
     <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     <html> <head>
     <title> %(title)s </title>
     </head>
     <body>
     <img src="https://portal.futuregrid.org/sites/default/files/u30/fg-logo-md.gif" width="94" height="65" alt="FutureGrid" /> Eucalyptus Monitor
     <h1> %(title)s </h1>
     <table>
     <tr>
     <td>
     <img src="pie.png" alt="chart" />
     </td>
     <td>
     <img src="bar.png" alt="chart" />
     </td>
     </tr>
     <tr>
     <td>
     Figure 1. Running instances per user of eucalyptus in India (pie type)
     </td>
     <td>
     Figure 2. Running instances per user of eucalyptus in India (bar type)
     </td>
     </tr>
     <tr>
     <td colspan="2">
     %(motion_chart)s
     </td>
     </tr>
     <tr>
     <td colspan="2">
     <br><br><br><br>
     Figure 3. Running instances per user of eucalyptus in India (motion chart)
     </td>
     </tr>
     </table>
     <hr>
     <address>Author Gregor von Laszewski, [email protected]</address>
     <!-- hhmts start -->Last modified: %(now)s <!-- hhmts end -->
     </body> </html>
     """
     print "========"
     now = datetime.now()
     now = "%s-%s-%s %s:%s:%s" %  (now.year, now.month, now.day, now.hour, now.minute, now.second)
     gmc = GoogleMotionChart()
     motion_chart = gmc.display(self.users, self.from_date)
     filename = output_dir+"/index.html"
     Utility.ensure_dir(filename)
     f = open(filename, "w")
     f.write(page_template % vars())
     f.close()
    def display_user_stats(self, type="pie", filepath="chart.png"):
        """ filepath = display, filepath = url, filepath = real filepath"""
        """displays the number of VMs a user is running"""
        """ types supported pie, bar"""

        values = []
        label_values = []

        #        print self.users
        
        max_v = 0
        for name in self.users:
            number = self.users[name]['count']
            values.append(number)
            label_values.append(name + ":" + str(number))
            max_v = max(max_v, number)

        # print values
        # print label_values

        if type == "pie": 
            chart = PieChart3D(500, 200)
            chart.set_pie_labels(label_values)
        if type == "bar":
            chart = StackedHorizontalBarChart(500,200,
                                            x_range=(0, max_v))
            # the labels seem wrong, not sure why i have to call reverse
            chart.set_axis_labels('y', reversed(label_values))
            # setting the x axis labels
            left_axis = range(0, max_v + 1, 1)
            left_axis[0] = ''
            chart.set_axis_labels(Axis.BOTTOM, left_axis)

            chart.set_bar_width(10)
            chart.set_colours(['00ff00', 'ff0000'])

        # Add some data
        chart.add_data(values)

        # Assign the labels to the pie data

        if filepath == "display":
            #os.system ("open -a /Applications/Safari.app " + '"' + url + '"')
            os.system ("open " + filepath)
        elif filepath == "url":
            url = chart.get_url()
            print url
        else:
            Utility.ensure_dir(filepath)
            chart.download(filepath)
 def make_html (self, output_dir, title):
     page_template = """
     <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     <html> <head>
     <title> %(title)s </title>
     </head>
     <body>
     <img src="fg-logo.png" alt="FutureGrid" /> Eucalyptus Monitor
     <h1> %(title)s </h1>
     <p>
     <img src="pie.png" alt="chart" /><img src="bar.png" alt="chart" />
     <hr>
     <address>Author Gregor von Laszewski, [email protected]</address>
     <!-- hhmts start -->Last modified: %(now)s <!-- hhmts end -->
     </body> </html>
     """
     print "========"
     now = datetime.now()
     now = "%s-%s-%s %s:%s:%s" %  (now.year, now.month, now.day, now.hour, now.minute, now.second)
     filename = output_dir+"/index.html"
     Utility.ensure_dir(filename)
     f = open(filename, "w")
     f.write(page_template % vars())
     f.close()
 def do_getdaterange(self, arg): #Get Date range of 'instances' table in mysql db
     res = self.instances.getDateRange()
     print Utility.convertOutput(res[0], "first_date")
     print Utility.convertOutput(res[1], "last_date")