Python time.year() Examples

The following are 10 code examples for showing how to use time.year(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module time , or try the search function .

Example 1
Project: rpi_ai   Author: schollz   File: visual_cortex.py    License: MIT License 6 votes vote down vote up
def saveImage():
	keepDiskSpaceFree(config.diskSpaceToReserve)
	time = datetime.datetime.now()
	filenameFull = config.filepath + config.filenamePrefix + "-%04d%02d%02d%02d%02d%02d" % (time.year, time.month, time.day, time.hour, time.minute, time.second)+ "." + config.fileType
	
	# save onto webserver
	filename = "/var/www/temp.jpg"
	subprocess.call("sudo raspistill -w "+ str(config.saveWidth) +" -h "+ str(config.saveHeight) + " -t 1 -n -vf -e " + config.fileType + " -q 15 -o %s" % filename, shell=True)
	print "Captured image: %s" % filename

	theSpeech = recognizeFace(filename,filenameFull)
	if len(theSpeech)>2:
		print theSpeech
		saySomething(theSpeech,"en")
		config.lookForFaces = 0


# Keep free space above given level 
Example 2
Project: augur   Author: nextstrain   File: frequency_estimators.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def timestamp_to_float(time):
    """Convert a pandas timestamp to a floating point date.

    >>> import datetime
    >>> time = datetime.date(2010, 10, 1)
    >>> timestamp_to_float(time)
    2010.75
    >>> time = datetime.date(2011, 4, 1)
    >>> timestamp_to_float(time)
    2011.25
    >>> timestamp_to_float(datetime.date(2011, 1, 1))
    2011.0
    >>> timestamp_to_float(datetime.date(2011, 12, 1)) == (2011.0 + 11.0 / 12)
    True
    """
    return time.year + ((time.month - 1) / 12.0) 
Example 3
Project: fluids   Author: CalebBell   File: spa.py    License: MIT License 6 votes vote down vote up
def julian_day_dt(year, month, day, hour, minute, second, microsecond):
    """This is the original way to calculate the julian day from the NREL paper.
    However, it is much faster to convert to unix/epoch time and then convert
    to julian day. Note that the date must be UTC."""
    # Not used anywhere!
    if month <= 2:
        year = year-1
        month = month+12
    a = int(year/100)
    b = 2 - a + int(a * 0.25)
    frac_of_day = (microsecond + (second + minute * 60 + hour * 3600)
                   ) * 1.0 / (3600*24)
    d = day + frac_of_day
    jd = (int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d +
          b - 1524.5)
    return jd 
Example 4
def get_date():
    '''
    This creates a string of the day, hour, minute and second
    I use this to make folder names unique
    
    For the files themselves, I generate genuinely unique names (i.e. name001.csv, name002.csv, etc.)
    '''
    time = datetime.datetime.now()
    time_str = "{}y{}m{}d{}h{}m{}s".format(time.year,time.month,time.day,time.hour,time.minute,time.second)
    return(time_str) 
Example 5
Project: augur   Author: nextstrain   File: frequency_estimators.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def float_to_datestring(time):
    """Convert a floating point date to a date string

    >>> float_to_datestring(2010.75)
    '2010-10-01'
    >>> float_to_datestring(2011.25)
    '2011-04-01'
    >>> float_to_datestring(2011.0)
    '2011-01-01'
    >>> float_to_datestring(2011.0 + 11.0 / 12)
    '2011-12-01'

    In some cases, the given float value can be truncated leading to unexpected
    conversion between floating point and integer values. This function should
    account for these errors by rounding months to the nearest integer.

    >>> float_to_datestring(2011.9166666666665)
    '2011-12-01'
    >>> float_to_datestring(2016.9609856262834)
    '2016-12-01'
    """
    year = int(time)

    # After accounting for the current year, extract the remainder and convert
    # it to a month using the inverse of the logic used to create the floating
    # point date. If the float date is sufficiently close to the end of the
    # year, rounding can produce a 13th month.
    month = min(int(np.rint(((time - year) * 12) + 1)), 12)

    # Floating point dates do not encode day information, so we always assume
    # they refer to the start of a given month.
    day = 1

    return "%s-%02d-%02d" % (year, month, day) 
Example 6
Project: augur   Author: nextstrain   File: frequency_estimators.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, sigma_narrow=1 / 12.0, sigma_wide=3 / 12.0, proportion_wide=0.2,
                 pivot_frequency=1, start_date=None, end_date=None, weights=None, weights_attribute=None,
                 node_filters=None, max_date=None, include_internal_nodes=False, censored=False):
        """Define parameters for KDE-based frequency estimation.

        Args:
            sigma_narrow (float): Bandwidth for first of two Gaussians composing the KDEs
            sigma_wide (float): Bandwidth for second of two Gaussians composing the KDEs
            proportion_wide (float): Proportion of the second Gaussian to include in each KDE
            pivot_frequency (int): Number of months between pivots
            start_date (float): start of the pivots interval
            end_date (float): end of the pivots interval
            weights (dict): Numerical weights indexed by attribute values and applied to individual tips
            weights_attribute (str): Attribute annotated on tips of a tree to use for weighting
            node_filters (dict): Mapping of node attribute names (keys) to a list of valid values to keep
            max_date (float): Maximum year beyond which tips are excluded from frequency estimation and are assigned
                              frequencies of zero
            include_internal_nodes (bool): Whether internal (non-tip) nodes should have their frequencies estimated
            censored (bool): Whether future observations should be censored at each pivot

        Returns:
            KdeFrequencies
        """
        self.sigma_narrow = sigma_narrow
        self.sigma_wide = sigma_wide
        self.proportion_wide = proportion_wide
        self.pivot_frequency = pivot_frequency
        self.start_date = start_date
        self.end_date = end_date
        self.weights = weights
        self.weights_attribute = weights_attribute
        self.node_filters = node_filters
        self.max_date = max_date
        self.include_internal_nodes = include_internal_nodes
        self.censored = censored 
Example 7
Project: Malicious_Domain_Whois   Author: h-j-13   File: get_data.py    License: GNU General Public License v3.0 5 votes vote down vote up
def update_redis():
    get_black_name(1)
    get_black_tel(1)
    get_black_email(1)
    get_malicious_domain_whois(1)
    get_malicious_sponsoring_registrar()
    get_malicious_tld()
    get_ip_frequency()
    get_exist_situation()
    get_update_situation()
    for year in range(2007, 2018):
        get_c_e_data(year) 
Example 8
Project: oggm   Author: OGGM   File: test_utils.py    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_date_to_floatyear(self):

        r = utils.date_to_floatyear(0, 1)
        self.assertEqual(r, 0)

        r = utils.date_to_floatyear(1, 1)
        self.assertEqual(r, 1)

        r = utils.date_to_floatyear([0, 1], [1, 1])
        np.testing.assert_array_equal(r, [0, 1])

        yr = utils.date_to_floatyear([1998, 1998], [6, 7])
        y, m = utils.floatyear_to_date(yr)
        np.testing.assert_array_equal(y, [1998, 1998])
        np.testing.assert_array_equal(m, [6, 7])

        yr = utils.date_to_floatyear([1998, 1998], [2, 3])
        y, m = utils.floatyear_to_date(yr)
        np.testing.assert_array_equal(y, [1998, 1998])
        np.testing.assert_array_equal(m, [2, 3])

        time = pd.date_range('1/1/1800', periods=300*12-11, freq='MS')
        yr = utils.date_to_floatyear(time.year, time.month)
        y, m = utils.floatyear_to_date(yr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        myr = utils.monthly_timeseries(1800, 2099)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        myr = utils.monthly_timeseries(1800, ny=300)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        time = pd.period_range('0001-01', '6000-1', freq='M')
        myr = utils.monthly_timeseries(1, 6000)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        time = pd.period_range('0001-01', '6000-12', freq='M')
        myr = utils.monthly_timeseries(1, 6000, include_last_year=True)
        y, m = utils.floatyear_to_date(myr)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        with self.assertRaises(ValueError):
            utils.monthly_timeseries(1) 
Example 9
Project: oggm   Author: OGGM   File: test_utils.py    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_hydro_convertion(self):

        # October
        y, m = utils.hydrodate_to_calendardate(1, 1, start_month=10)
        assert (y, m) == (0, 10)
        y, m = utils.hydrodate_to_calendardate(1, 4, start_month=10)
        assert (y, m) == (1, 1)
        y, m = utils.hydrodate_to_calendardate(1, 12, start_month=10)
        assert (y, m) == (1, 9)

        y, m = utils.hydrodate_to_calendardate([1, 1, 1], [1, 4, 12],
                                               start_month=10)
        np.testing.assert_array_equal(y, [0, 1, 1])
        np.testing.assert_array_equal(m, [10, 1, 9])

        y, m = utils.calendardate_to_hydrodate(1, 1, start_month=10)
        assert (y, m) == (1, 4)
        y, m = utils.calendardate_to_hydrodate(1, 9, start_month=10)
        assert (y, m) == (1, 12)
        y, m = utils.calendardate_to_hydrodate(1, 10, start_month=10)
        assert (y, m) == (2, 1)

        y, m = utils.calendardate_to_hydrodate([1, 1, 1], [1, 9, 10],
                                               start_month=10)
        np.testing.assert_array_equal(y, [1, 1, 2])
        np.testing.assert_array_equal(m, [4, 12, 1])

        # Roundtrip
        time = pd.period_range('0001-01', '1000-12', freq='M')
        y, m = utils.calendardate_to_hydrodate(time.year, time.month,
                                               start_month=10)
        y, m = utils.hydrodate_to_calendardate(y, m, start_month=10)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month)

        # April
        y, m = utils.hydrodate_to_calendardate(1, 1, start_month=4)
        assert (y, m) == (0, 4)
        y, m = utils.hydrodate_to_calendardate(1, 4, start_month=4)
        assert (y, m) == (0, 7)
        y, m = utils.hydrodate_to_calendardate(1, 9, start_month=4)
        assert (y, m) == (0, 12)
        y, m = utils.hydrodate_to_calendardate(1, 10, start_month=4)
        assert (y, m) == (1, 1)
        y, m = utils.hydrodate_to_calendardate(1, 12, start_month=4)
        assert (y, m) == (1, 3)

        y, m = utils.hydrodate_to_calendardate([1, 1, 1], [1, 4, 12],
                                               start_month=4)
        np.testing.assert_array_equal(y, [0, 0, 1])
        np.testing.assert_array_equal(m, [4, 7, 3])

        # Roundtrip
        time = pd.period_range('0001-01', '1000-12', freq='M')
        y, m = utils.calendardate_to_hydrodate(time.year, time.month,
                                               start_month=4)
        y, m = utils.hydrodate_to_calendardate(y, m, start_month=4)
        np.testing.assert_array_equal(y, time.year)
        np.testing.assert_array_equal(m, time.month) 
Example 10
Project: Malicious_Domain_Whois   Author: h-j-13   File: get_data1.py    License: GNU General Public License v3.0 4 votes vote down vote up
def get_c_e_data(chooseyear):

    date_data = dict(year=[{"name":"一月", "cValue":0, "eValue":0}, {"name":"二月", "cValue":0, "eValue":0}, {"name":"三月", "cValue":0, "eValue":0}, {"name":"四月", "cValue":0, "eValue":0}, {"name":"五月", "cValue":0, "eValue":0}, {"name":"六月", "cValue":0, "eValue":0}, {"name":"七月", "cValue":0, "eValue":0}, {"name":"八月", "cValue":0, "eValue":0}, {"name":"九月", "cValue":0, "eValue":0}, {"name":"十月", "cValue":0, "eValue":0}, {"name":"十一月", "cValue":0, "eValue":0}, {"name":"十二月", "cValue":0, "eValue":0}], c_date=[], e_date=[])

    standard_year = 2003
    for year in range(standard_year, chooseyear+1):
        date_data['c_date'].append({"name": year,"value":0})
        date_data['e_date'].append({"name": year, "value": 0})

    data = whois.select(whois.creation_date).where(whois.creation_date != '')
    for date in data:
        try:
            try:
                time = arrow.get(date.creation_date, 'DD-MMM-YYYY')
                date_data['c_date'][time.year-standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month-1]["cValue"] += 1

            except:
                time = arrow.get(date.creation_date)
                date_data['c_date'][time.year - standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month - 1]["cValue"] += 1

        except:
            pass

    data1 = whois.select(whois.expiration_date).where(whois.expiration_date != '')

    for date in data1:
        try:
            try:
                time = arrow.get(date.expiration_date, 'DD-MMM-YYYY')
                date_data['e_date'][time.year - standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month - 1]["eValue"] += 1

            except:
                time = arrow.get(date.expiration_date)
                date_data['e_date'][time.year - standard_year]['value'] += 1
                if time.year == chooseyear:
                    date_data['year'][time.month - 1]["eValue"] += 1

        except:
            pass

    return json.dumps(date_data, ensure_ascii=False)

# 4.2恶意域名总体生存时间分布展示   横轴动态定