Пример #1
0
 def test_data(self):
     types = ["Python", "Ruby", "Lua", "CSS", "Java", "JavaScript"]
     for i in range(0, 100, 5):
         title = str(i) + ".Pastebin_for_test_code"
         type = random.choice(types)
         time = fmt_time()
         sql = (
             'INSERT INTO posts(title, poster, type, content, time, password) \
         values("%s", "test", "%s", "#!/usr/bin/env python","%s","1")'
             % (title, type, time)
         )
         self.cur.execute(sql)
         self.conn.commit()
Пример #2
0
 def post(self,id):
     if self.check_login(id):
         id = int(id)
         url = '/detail/' + str(id)
         title = xhtml_escape(self.get_argument('title', ''))
         poster = xhtml_escape(self.get_argument('poster', ''))
         password = xhtml_escape(self.get_argument('password', ''))
         type = xhtml_escape(self.get_argument('syntax', 'other'))
         content = xhtml_escape(self.get_argument('content', ''))
         time = fmt_time()
         Post.modify(id, title, poster, type, content, time, password)
         self.redirect(url) 
     else:
         self.redirect('/detail/' + str(id))
Пример #3
0
    def post(self):
        title = xhtml_escape(self.get_argument('title', ''))
        poster = xhtml_escape(self.get_argument('poster', ''))
        password = xhtml_escape(self.get_argument('password', ''))
        type = xhtml_escape(self.get_argument('syntax', 'other'))
        content = xhtml_escape(self.get_argument('content', ''))
        time = fmt_time()
        Post.add(title, poster, type, content, time, password)
        self.redirect('/')

        


        

        



        
            
Пример #4
0
def today():
    return fmt_time('%Y-%m-%d')
Пример #5
0
def fmt(seconds, f='%Y-%m-%d %H:%M:%S'):
    return fmt_time(f, seconds)
Пример #6
0
def main(profile=False, sds_fn=None):

    if not PROFILE:
        end = input("Begin simulation? ('n' to break) ") == 'n'
        if end: sys.exit()

    print("\nBEGINNING MAIN ROUTINE")

    if sds_fn is None:
        # Generate list of Superdroplets
        sds = [Superdroplet(xi_i, r**3., 0.) for r in r_grid]
    else:
        # Load from sds_fn
        with open(sds_fn, "rb") as f:
            sds = pickle.load(f)

    sds = to_sd_array(sds)
    wm0 = np.sum([s.multi * s.mass for s in sds]) / 1e3
    sdss = [
        sort_sds(sds),
    ]
    print("Initial water mass = ", wm0)

    results = []

    c_step = partial(cython_step, t_c=t_c, delta_V=delta_V, kern=kernel)

    t, ti = 0., 0
    n_drops = len(sds)
    n_init = n_drops * 1
    wms = [
        np.sum([s.multi * s.mass for s in sds]) / 1e3,
    ]
    xi_s = [
        np.sum([s.multi for s in sds]),
    ]

    color_map = OrderedDict(initial='k')

    while t < t_end:
        ti += 1
        t = ti * t_c  # diagnose time from step to avoid accumulating
        # floating point errors which screw things up

        minutes, seconds = s_to_min_s(t)

        if profile and ti > 10:
            break

        print("STEP %d (%s)" % (ti, fmt_time(minutes, seconds)))
        print(ti, out_dt, ti % out_dt, is_output_step(ti))
        print(minutes, seconds)

        sds = c_step(sds)
        # sds = recycle(sds)
        sds = to_sd_array(sds)

        print(len(sds))
        if len(sds) < n_drops:
            print("   Lost %d superdrops" % (n_drops - len(sds), ))
            n_drops = len(sds)
        else:
            print("   No change in superdrop number")

        if is_output_step(ti):
            if DIAG_PLOTS:

                minutes_str = fmt_time(minutes, seconds, True)

                xx, yy = kde_plot(sds)
                plt.figure(1)
                lines = plt.plot(xx, yy, lw=2.5, label=minutes_str)
                l = lines[0]
                results.append(yy)

                r_centers, gyt = \
                    bin_mass_density(sds, True, n_bins=41,
                                     log_r_min=-7, log_r_max=np.log(5e-2))
                r_centers *= 1e6 * 10
                plt.plot(
                    r_centers,
                    gyt,
                    ls='--',
                    color=l.get_color(),
                    # label='%s [binned]' % minutes_str
                )

                color_map[minutes_str] = l.get_color()

                plt.draw()

            if SAVE_SDS:
                save_fn = "{}_{}m_{}s.sds".format(casename, minutes, seconds)

                with open(save_fn, 'wb') as f:
                    pickle.dump(sds, f)

        if n_drops < n_init / (2**3):
            if DIAG_PLOTS:
                xx, yy = kde_plot(sds)
                plt.figure(1)
                plt.plot(xx, yy, label='crash')
                plt.draw()

            print("Superdroplet number dropped too low")
            break

        if is_output_step(ti):
            wms.append(np.sum([s.multi * s.mass for s in sds]) / 1e3)
            xi_s.append(np.sum([s.multi for s in sds]))
            sdss.append(sort_sds(sds))
        print("--" * 40)

    if DIAG_PLOTS:
        xx, yy = kde_plot(sds)
        plt.figure(1)
        # plt.plot(xx, yy, '-b', label='final')
        plt.legend(loc='best')

        ax = plt.gca()
        colortext_legend(color_map,
                         ax,
                         fontsize=14,
                         loc='upper left',
                         bbox_to_anchor=(-0.1, 1.0))

        plt.draw()

        ## Additional diagnostics -
        ## 1) total water mass, black (should be flat)
        ## 2) total SD number, red (should decrease over time)
        # plt.figure(2)
        # plt.clf()
        # plt.plot(wms, color='k')
        # plt.twinx()
        # plt.plot(xi_s, color='r')
        # plt.legend()

        plt.show()

    return wms, xi_s, sdss
Пример #7
0
def main(profile=False):

    print()
    print("BEGINNING MAIN ROUTINE")

    # Generate list of Superdroplets
    sds = [Superdroplet(xi_i, r**3., 0.) for r in r_grid]
    sds = to_sd_array(sds)
    wm0 = np.sum([s.multi * s.mass for s in sds]) / 1e3
    sdss = [
        sort_sds(sds),
    ]
    print("Initial water mass = ", wm0)

    if not PROFILE:
        end = input("Begin simulation? ('n' to break) ") == 'n'
        if end: sys.exit()

    results = []

    c_step = partial(cython_step, t_c=t_c, delta_V=delta_V, kern=kernel)

    t, ti = 0., 0
    n_drops = len(sds)
    n_init = n_drops * 1
    wms = [
        np.sum([s.multi * s.mass for s in sds]) / 1e3,
    ]
    xi_s = [
        np.sum([s.multi for s in sds]),
    ]

    color_map = OrderedDict(initial='k')

    while t < t_end:

        minutes, seconds = s_to_min_s(t)

        if profile and ti > 10:
            break

        print("STEP %d (%s)" % (ti, fmt_time(minutes, seconds)))
        print(ti, out_dt, ti % out_dt, is_output_step(ti))
        print(minutes, seconds)

        sds = c_step(sds)
        # sds = recycle(sds)
        sds = to_sd_array(sds)

        print(len(sds))
        if len(sds) < n_drops:
            print("   Lost %d superdrops" % (n_drops - len(sds), ))
            n_drops = len(sds)
        else:
            print("   No change in superdrop number")

        print()

        if (is_output_step(ti) or is_plot_step(ti)) and \
           (DIAG_PLOTS or WRITE_OUT):

            # pre-compute KDE data for plotting/saving
            xx, yy = kde_plot(sds, delta_V=delta_V)

        if is_output_step(ti) and WRITE_OUT and (ti > 0):
            # save KDE-estimate of droplet size distribution
            output_df = pd.DataFrame({'size': xx, 'wm': yy})
            output_df.to_csv("out_{:04d}.csv".format(int(t)), index=False)

            wms.append(np.sum([s.multi * s.mass for s in sds]) / 1e3)
            xi_s.append(np.sum([s.multi for s in sds]))
            sdss.append(sort_sds(sds))

        if DIAG_PLOTS and is_plot_step(ti) and (ti > 0):

            minutes_str = fmt_time(minutes, seconds, True)

            plt.figure(1)
            lines = plt.plot(xx, yy, lw=2.5, label=minutes_str)
            l = lines[0]
            results.append(yy)

            r_centers, gyt = \
                bin_mass_density(sds, True, n_bins=41,
                                 log_r_min=-7, log_r_max=np.log(5e-2),
                                 delta_V=delta_V)

            r_centers *= 1e6 * 10
            plt.plot(
                r_centers,
                gyt,
                ls='--',
                color=l.get_color(),
                # label='%s [binned]' % minutes_str
            )

            color_map[minutes_str] = l.get_color()

            plt.draw()

        if n_drops < n_init / (2**3):
            if DIAG_PLOTS:
                xx, yy = kde_plot(sds, delta_V=delta_V)
                plt.figure(1)
                plt.plot(xx, yy, label='crash')
                plt.draw()

            print("Superdroplet number dropped too low")
            break

        print("--" * 40)

        ti += 1
        t = ti * t_c  # diagnose time from step to avoid accumulating
        # floating point errors which screw things up

    if DIAG_PLOTS:
        xx, yy = kde_plot(sds, delta_V=delta_V)
        plt.figure(1)
        # plt.plot(xx, yy, '-b', label='final')
        plt.legend(loc='best')

        ax = plt.gca()
        colortext_legend(color_map,
                         ax,
                         fontsize=14,
                         loc='upper left',
                         bbox_to_anchor=(-0.1, 1.0))

        plt.draw()

        ## Additional diagnostics -
        ## 1) total water mass, black (should be flat)
        ## 2) total SD number, red (should decrease over time)
        # plt.figure(2)
        # plt.clf()
        # plt.plot(wms, color='k')
        # plt.twinx()
        # plt.plot(xi_s, color='r')
        # plt.legend()

        plt.show()

    return wms, xi_s, sdss
Пример #8
0
def main(profile=False):

    if not PROFILE:
        end = raw_input("Begin simulation? ('n' to break) ") == 'n'
        if end: sys.exit() 


    print
    print "BEGINNING MAIN ROUTINE"

    # Generate list of Superdroplets
    sds = [Superdroplet(xi_i, r**3., 0.) for r in r_grid]
    sds = to_sd_array(sds)
    wm0 = np.sum([s.multi*s.mass for s in sds])/1e3
    sdss = [sort_sds(sds), ]
    print "Initial water mass = ", wm0

    results = []

    c_step = partial(cython_step, t_c=t_c, delta_V=delta_V,
                     kern=kernel)

    t, ti = 0., 0
    n_drops = len(sds)
    n_init = n_drops*1
    wms = [np.sum([s.multi*s.mass for s in sds])/1e3, ]
    xi_s = [np.sum([s.multi for s in sds]), ]

    color_map = OrderedDict(initial='k')

    while t < t_end:
        ti += 1
        t = ti * t_c # diagnose time from step to avoid accumulating
                     # floating point errors which screw things up

        minutes, seconds = s_to_min_s(t)

        if profile and ti > 10:
            break

        print "STEP %d (%s)" % (ti, fmt_time(minutes, seconds))
        print ti, out_dt, ti % out_dt, is_output_step(ti)
        print minutes, seconds

        sds = c_step(sds)
        sds = recycle(sds)
        # sds = to_sd_array(sds)

        print len(sds)
        if len(sds) < n_drops:
            print "   Lost %d superdrops" % (n_drops - len(sds), )
            n_drops = len(sds)
        else:
            print "   No change in superdrop number"

        print

        if is_output_step(ti):
            if DIAG_PLOTS:

                minutes_str = fmt_time(minutes, seconds, True)

                xx, yy = kde_plot(sds)
                plt.figure(1)
                lines = plt.plot(xx, yy, lw=2.5, label=minutes_str)
                l = lines[0]
                results.append(yy)

                r_centers, gyt = \
                    bin_mass_density(sds, True, n_bins=41, 
                                     log_r_min=-7, log_r_max=np.log(5e-2))
                r_centers *= 1e6 * 10
                plt.plot(r_centers, gyt, ls='--', color=l.get_color(),
                        # label='%s [binned]' % minutes_str
                )

                color_map[minutes_str] = l.get_color()

                plt.draw()

        if n_drops < n_init/(2**3):            
            if DIAG_PLOTS:
                xx, yy = kde_plot(sds)
                plt.figure(1)
                plt.plot(xx, yy, label='crash')
                plt.draw()

            print "Superdroplet number dropped too low"
            break

        if is_output_step(ti):
            wms.append(np.sum([s.multi*s.mass for s in sds])/1e3)
            xi_s.append(np.sum([s.multi for s in sds]))
            sdss.append(sort_sds(sds))
        print "--"*40

    if DIAG_PLOTS:
        xx, yy = kde_plot(sds)
        plt.figure(1)
        # plt.plot(xx, yy, '-b', label='final')
        plt.legend(loc='best')

        ax = plt.gca()
        colortext_legend(color_map, ax, fontsize=14, 
                         loc='upper left',
                         bbox_to_anchor=(-0.1, 1.0))

        plt.draw()

        ## Additional diagnostics - 
        ## 1) total water mass, black (should be flat)
        ## 2) total SD number, red (should decrease over time)
        # plt.figure(2)
        # plt.clf()
        # plt.plot(wms, color='k')
        # plt.twinx()
        # plt.plot(xi_s, color='r')
        # plt.legend()

        plt.show()

    return wms, xi_s, sdss
Пример #9
0
 def request_time_info(self):
     return '<!-- generated when %s, use %fms -->' % (
         fmt_time(), self.request.request_time())
Пример #10
0
def today():
    return fmt_time('%Y-%m-%d')
Пример #11
0
def fmt(seconds, f='%Y-%m-%d %H:%M:%S'):
    return fmt_time(f, seconds)
Пример #12
0
 def request_time_info(self):
     return '<!-- generated when %s, use %fms -->' % (fmt_time(), self.request.request_time())