Best Python code snippet using autotest_python
ephemerides.py
Source:ephemerides.py
1#!/usr/bin/env python32# Kosmorrolib - The Library To Compute Your Ephemerides3# Copyright (C) 2021 Jérôme Deuchnord <jerome@deuchnord.fr>4#5# This program is free software: you can redistribute it and/or modify6# it under the terms of the GNU Affero General Public License as7# published by the Free Software Foundation, either version 3 of the8# License, or (at your option) any later version.9#10# This program is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU Affero General Public License for more details.14#15# You should have received a copy of the GNU Affero General Public License16# along with this program. If not, see <https://www.gnu.org/licenses/>.17from datetime import date, datetime, timedelta18from typing import Union19from skyfield.searchlib import find_discrete, find_maxima20from skyfield.timelib import Time21from skyfield.constants import tau22from skyfield.errors import EphemerisRangeError23from .model import Position, AsterEphemerides, MoonPhase, Object, ASTERS24from .dateutil import translate_to_timezone, normalize_datetime25from .core import get_skf_objects, get_timescale, get_iau2000b26from .enum import MoonPhaseType27from .exceptions import OutOfRangeDateError28RISEN_ANGLE = -0.833329def _get_skyfield_to_moon_phase(30 times: [Time], vals: [int], now: Time, timezone: int31) -> Union[MoonPhase, None]:32 tomorrow = get_timescale().utc(33 now.utc_datetime().year, now.utc_datetime().month, now.utc_datetime().day + 134 )35 next_phase_time = None36 i = 037 # Find the current moon phase:38 for i, time in enumerate(times):39 if now.utc_datetime() <= time.utc_datetime():40 if time.utc_datetime() >= tomorrow.utc_datetime():41 i -= 142 break43 current_phase = MoonPhaseType(vals[i])44 if current_phase in [45 MoonPhaseType.NEW_MOON,46 MoonPhaseType.FIRST_QUARTER,47 MoonPhaseType.FULL_MOON,48 MoonPhaseType.LAST_QUARTER,49 ]:50 current_phase_time = translate_to_timezone(times[i].utc_datetime(), timezone)51 else:52 current_phase_time = None53 # Find the next moon phase54 for j in range(i + 1, len(times)):55 if vals[j] in [0, 2, 4, 6]:56 next_phase_time = translate_to_timezone(times[j].utc_datetime(), timezone)57 break58 return MoonPhase(current_phase, current_phase_time, next_phase_time)59def get_moon_phase(for_date: date = date.today(), timezone: int = 0) -> MoonPhase:60 """Calculate and return the moon phase for the given date, adjusted to the given timezone if any.61 Get the moon phase for the 27 March, 2021:62 >>> get_moon_phase(date(2021, 3, 27))63 <MoonPhase phase_type=MoonPhaseType.WAXING_GIBBOUS time=None next_phase_date=2021-03-28 18:48:10.902298+00:00>64 When the moon phase is a new moon, a first quarter, a full moon or a last quarter, you get the exact time65 of its happening too:66 >>> get_moon_phase(datetime(2021, 3, 28))67 <MoonPhase phase_type=MoonPhaseType.FULL_MOON time=2021-03-28 18:48:10.902298+00:00 next_phase_date=2021-04-04 10:02:27.393689+00:00>68 Get the moon phase for the 27 March, 2021, in the UTC+2 timezone:69 >>> get_moon_phase(date(2021, 3, 27), timezone=2)70 <MoonPhase phase_type=MoonPhaseType.WAXING_GIBBOUS time=None next_phase_date=2021-03-28 20:48:10.902298+02:00>71 Note that the moon phase can only be computed for a date range.72 Asking for the moon phase with an out of range date will result in an exception:73 >>> get_moon_phase(date(1000, 1, 1))74 Traceback (most recent call last):75 ...76 kosmorrolib.exceptions.OutOfRangeDateError: The date must be between 1899-08-09 and 2053-09-2677 """78 earth = get_skf_objects()["earth"]79 moon = get_skf_objects()["moon"]80 sun = get_skf_objects()["sun"]81 def moon_phase_at(time: Time):82 time._nutation_angles = get_iau2000b(time)83 current_earth = earth.at(time)84 _, mlon, _ = current_earth.observe(moon).apparent().ecliptic_latlon("date")85 _, slon, _ = current_earth.observe(sun).apparent().ecliptic_latlon("date")86 return (((mlon.radians - slon.radians) // (tau / 8)) % 8).astype(int)87 moon_phase_at.rough_period = 7.0 # one lunar phase per week88 today = get_timescale().utc(for_date.year, for_date.month, for_date.day)89 start_time = get_timescale().utc(for_date.year, for_date.month, for_date.day - 10)90 end_time = get_timescale().utc(for_date.year, for_date.month, for_date.day + 10)91 try:92 times, phases = find_discrete(start_time, end_time, moon_phase_at)93 return _get_skyfield_to_moon_phase(times, phases, today, timezone)94 except EphemerisRangeError as error:95 start = translate_to_timezone(error.start_time.utc_datetime(), timezone)96 end = translate_to_timezone(error.end_time.utc_datetime(), timezone)97 start = date(start.year, start.month, start.day) + timedelta(days=12)98 end = date(end.year, end.month, end.day) - timedelta(days=12)99 raise OutOfRangeDateError(start, end) from error100def get_ephemerides(101 position: Position, for_date: date = date.today(), timezone: int = 0102) -> [AsterEphemerides]:103 """Compute and return the ephemerides for the given position and date, adjusted to the given timezone if any.104 Compute the ephemerides for July 7th, 2022:105 >>> get_ephemerides(Position(36.6794, 4.8555), date(2022, 7, 7))106 [<AsterEphemerides rise_time=2022-07-07 04:29:00 culmination_time=2022-07-07 11:46:00 set_time=2022-07-07 19:02:00 aster=<Object type=STAR name=SUN />>,107 <AsterEphemerides rise_time=2022-07-07 12:16:00 culmination_time=2022-07-07 18:06:00 set_time=2022-07-07 23:54:00 aster=<Object type=SATELLITE name=MOON />>,108 <AsterEphemerides rise_time=2022-07-07 03:36:00 culmination_time=2022-07-07 10:58:00 set_time=2022-07-07 18:20:00 aster=<Object type=PLANET name=MERCURY />>,109 <AsterEphemerides rise_time=2022-07-07 02:30:00 culmination_time=2022-07-07 09:44:00 set_time=2022-07-07 16:58:00 aster=<Object type=PLANET name=VENUS />>,110 <AsterEphemerides rise_time=2022-07-07 00:05:00 culmination_time=2022-07-07 06:39:00 set_time=2022-07-07 13:14:00 aster=<Object type=PLANET name=MARS />>,111 <AsterEphemerides rise_time=2022-07-07 22:59:00 culmination_time=2022-07-07 05:11:00 set_time=2022-07-07 11:20:00 aster=<Object type=PLANET name=JUPITER />>,112 <AsterEphemerides rise_time=2022-07-07 21:06:00 culmination_time=2022-07-07 02:29:00 set_time=2022-07-07 07:48:00 aster=<Object type=PLANET name=SATURN />>,113 <AsterEphemerides rise_time=2022-07-07 00:47:00 culmination_time=2022-07-07 07:42:00 set_time=2022-07-07 14:38:00 aster=<Object type=PLANET name=URANUS />>,114 <AsterEphemerides rise_time=2022-07-07 22:27:00 culmination_time=2022-07-07 04:25:00 set_time=2022-07-07 10:20:00 aster=<Object type=PLANET name=NEPTUNE />>,115 <AsterEphemerides rise_time=2022-07-07 19:46:00 culmination_time=2022-07-07 00:41:00 set_time=2022-07-07 05:33:00 aster=<Object type=PLANET name=PLUTO />>]116 Timezone can be optionnaly set to adapt the hours to your location:117 >>> get_ephemerides(Position(36.6794, 4.8555), date(2022, 7, 7), timezone=2)118 [<AsterEphemerides rise_time=2022-07-07 06:29:00 culmination_time=2022-07-07 13:46:00 set_time=2022-07-07 21:02:00 aster=<Object type=STAR name=SUN />>,119 <AsterEphemerides rise_time=2022-07-07 14:16:00 culmination_time=2022-07-07 20:06:00 set_time=2022-07-07 01:27:00 aster=<Object type=SATELLITE name=MOON />>,120 <AsterEphemerides rise_time=2022-07-07 05:36:00 culmination_time=2022-07-07 12:58:00 set_time=2022-07-07 20:20:00 aster=<Object type=PLANET name=MERCURY />>,121 <AsterEphemerides rise_time=2022-07-07 04:30:00 culmination_time=2022-07-07 11:44:00 set_time=2022-07-07 18:58:00 aster=<Object type=PLANET name=VENUS />>,122 <AsterEphemerides rise_time=2022-07-07 02:05:00 culmination_time=2022-07-07 08:39:00 set_time=2022-07-07 15:14:00 aster=<Object type=PLANET name=MARS />>,123 <AsterEphemerides rise_time=2022-07-07 01:02:00 culmination_time=2022-07-07 07:11:00 set_time=2022-07-07 13:20:00 aster=<Object type=PLANET name=JUPITER />>,124 <AsterEphemerides rise_time=2022-07-07 23:06:00 culmination_time=2022-07-07 04:29:00 set_time=2022-07-07 09:48:00 aster=<Object type=PLANET name=SATURN />>,125 <AsterEphemerides rise_time=2022-07-07 02:47:00 culmination_time=2022-07-07 09:42:00 set_time=2022-07-07 16:38:00 aster=<Object type=PLANET name=URANUS />>,126 <AsterEphemerides rise_time=2022-07-07 00:31:00 culmination_time=2022-07-07 06:25:00 set_time=2022-07-07 12:20:00 aster=<Object type=PLANET name=NEPTUNE />>,127 <AsterEphemerides rise_time=2022-07-07 21:46:00 culmination_time=2022-07-07 02:41:00 set_time=2022-07-07 07:33:00 aster=<Object type=PLANET name=PLUTO />>]128 Objects may not rise or set on the given date (e.g. they rise the previous day or set the next day).129 In this case, you will get `None` values on the rise or set time.130 If an objet does not rise nor set due to your latitude, then both rise and set will be `None`:131 >>> north_pole = Position(70, 20)132 >>> south_pole = Position(-70, 20)133 >>> get_ephemerides(north_pole, date(2021, 6, 20))134 [<AsterEphemerides rise_time=None culmination_time=2021-06-20 10:42:00 set_time=None aster=<Object type=STAR name=SUN />>,135 <AsterEphemerides rise_time=2021-06-20 14:30:00 culmination_time=2021-06-20 18:44:00 set_time=2021-06-20 22:53:00 aster=<Object type=SATELLITE name=MOON />>,136 <AsterEphemerides rise_time=2021-06-20 22:56:00 culmination_time=2021-06-20 09:47:00 set_time=2021-06-20 20:34:00 aster=<Object type=PLANET name=MERCURY />>,137 <AsterEphemerides rise_time=None culmination_time=2021-06-20 12:20:00 set_time=None aster=<Object type=PLANET name=VENUS />>,138 <AsterEphemerides rise_time=None culmination_time=2021-06-20 13:17:00 set_time=None aster=<Object type=PLANET name=MARS />>,139 <AsterEphemerides rise_time=2021-06-20 23:06:00 culmination_time=2021-06-20 03:04:00 set_time=2021-06-20 06:58:00 aster=<Object type=PLANET name=JUPITER />>,140 <AsterEphemerides rise_time=2021-06-20 23:28:00 culmination_time=2021-06-20 01:48:00 set_time=2021-06-20 04:05:00 aster=<Object type=PLANET name=SATURN />>,141 <AsterEphemerides rise_time=2021-06-20 21:53:00 culmination_time=2021-06-20 07:29:00 set_time=2021-06-20 17:02:00 aster=<Object type=PLANET name=URANUS />>,142 <AsterEphemerides rise_time=2021-06-20 22:51:00 culmination_time=2021-06-20 04:22:00 set_time=2021-06-20 09:50:00 aster=<Object type=PLANET name=NEPTUNE />>,143 <AsterEphemerides rise_time=None culmination_time=2021-06-20 00:40:00 set_time=None aster=<Object type=PLANET name=PLUTO />>]144 >>> get_ephemerides(north_pole, date(2021, 12, 21))145 [<AsterEphemerides rise_time=None culmination_time=2021-12-21 10:38:00 set_time=None aster=<Object type=STAR name=SUN />>,146 <AsterEphemerides rise_time=None culmination_time=2021-12-21 00:04:00 set_time=None aster=<Object type=SATELLITE name=MOON />>,147 <AsterEphemerides rise_time=None culmination_time=2021-12-21 11:33:00 set_time=None aster=<Object type=PLANET name=MERCURY />>,148 <AsterEphemerides rise_time=2021-12-21 11:58:00 culmination_time=2021-12-21 12:33:00 set_time=2021-12-21 13:08:00 aster=<Object type=PLANET name=VENUS />>,149 <AsterEphemerides rise_time=None culmination_time=2021-12-21 08:54:00 set_time=None aster=<Object type=PLANET name=MARS />>,150 <AsterEphemerides rise_time=2021-12-21 11:07:00 culmination_time=2021-12-21 14:43:00 set_time=2021-12-21 18:19:00 aster=<Object type=PLANET name=JUPITER />>,151 <AsterEphemerides rise_time=2021-12-21 11:32:00 culmination_time=2021-12-21 13:33:00 set_time=2021-12-21 15:33:00 aster=<Object type=PLANET name=SATURN />>,152 <AsterEphemerides rise_time=2021-12-21 09:54:00 culmination_time=2021-12-21 19:13:00 set_time=2021-12-21 04:37:00 aster=<Object type=PLANET name=URANUS />>,153 <AsterEphemerides rise_time=2021-12-21 10:49:00 culmination_time=2021-12-21 16:05:00 set_time=2021-12-21 21:21:00 aster=<Object type=PLANET name=NEPTUNE />>,154 <AsterEphemerides rise_time=None culmination_time=2021-12-21 12:31:00 set_time=None aster=<Object type=PLANET name=PLUTO />>]155 >>> get_ephemerides(south_pole, date(2021, 6, 20))156 [<AsterEphemerides rise_time=None culmination_time=2021-06-20 10:42:00 set_time=None aster=<Object type=STAR name=SUN />>,157 <AsterEphemerides rise_time=2021-06-20 11:10:00 culmination_time=2021-06-20 19:06:00 set_time=2021-06-20 01:20:00 aster=<Object type=SATELLITE name=MOON />>,158 <AsterEphemerides rise_time=2021-06-20 07:47:00 culmination_time=2021-06-20 09:47:00 set_time=2021-06-20 11:48:00 aster=<Object type=PLANET name=MERCURY />>,159 <AsterEphemerides rise_time=None culmination_time=2021-06-20 12:20:00 set_time=None aster=<Object type=PLANET name=VENUS />>,160 <AsterEphemerides rise_time=2021-06-20 12:14:00 culmination_time=2021-06-20 13:17:00 set_time=2021-06-20 14:21:00 aster=<Object type=PLANET name=MARS />>,161 <AsterEphemerides rise_time=2021-06-20 18:32:00 culmination_time=2021-06-20 03:04:00 set_time=2021-06-20 11:32:00 aster=<Object type=PLANET name=JUPITER />>,162 <AsterEphemerides rise_time=2021-06-20 15:20:00 culmination_time=2021-06-20 01:48:00 set_time=2021-06-20 12:12:00 aster=<Object type=PLANET name=SATURN />>,163 <AsterEphemerides rise_time=2021-06-20 04:32:00 culmination_time=2021-06-20 07:29:00 set_time=2021-06-20 10:26:00 aster=<Object type=PLANET name=URANUS />>,164 <AsterEphemerides rise_time=2021-06-20 21:28:00 culmination_time=2021-06-20 04:22:00 set_time=2021-06-20 11:13:00 aster=<Object type=PLANET name=NEPTUNE />>,165 <AsterEphemerides rise_time=None culmination_time=2021-06-20 00:40:00 set_time=None aster=<Object type=PLANET name=PLUTO />>]166 >>> get_ephemerides(south_pole, date(2021, 12, 22))167 [<AsterEphemerides rise_time=None culmination_time=2021-12-22 10:39:00 set_time=None aster=<Object type=STAR name=SUN />>,168 <AsterEphemerides rise_time=None culmination_time=2021-12-22 01:01:00 set_time=None aster=<Object type=SATELLITE name=MOON />>,169 <AsterEphemerides rise_time=None culmination_time=2021-12-22 11:35:00 set_time=None aster=<Object type=PLANET name=MERCURY />>,170 <AsterEphemerides rise_time=None culmination_time=2021-12-22 12:27:00 set_time=None aster=<Object type=PLANET name=VENUS />>,171 <AsterEphemerides rise_time=None culmination_time=2021-12-22 08:53:00 set_time=None aster=<Object type=PLANET name=MARS />>,172 <AsterEphemerides rise_time=2021-12-22 05:52:00 culmination_time=2021-12-22 14:40:00 set_time=2021-12-22 23:26:00 aster=<Object type=PLANET name=JUPITER />>,173 <AsterEphemerides rise_time=2021-12-22 02:41:00 culmination_time=2021-12-22 13:29:00 set_time=2021-12-22 00:21:00 aster=<Object type=PLANET name=SATURN />>,174 <AsterEphemerides rise_time=2021-12-22 16:01:00 culmination_time=2021-12-22 19:09:00 set_time=2021-12-22 22:17:00 aster=<Object type=PLANET name=URANUS />>,175 <AsterEphemerides rise_time=2021-12-22 08:59:00 culmination_time=2021-12-22 16:01:00 set_time=2021-12-22 23:04:00 aster=<Object type=PLANET name=NEPTUNE />>,176 <AsterEphemerides rise_time=None culmination_time=2021-12-22 12:27:00 set_time=None aster=<Object type=PLANET name=PLUTO />>]177 Please note:178 - The ephemerides can only be computed for a date range. Asking for the ephemerides with an out of range date will result in an exception:179 >>> get_ephemerides(Position(50.5824, 3.0624), date(1000, 1, 1))180 Traceback (most recent call last):181 ...182 kosmorrolib.exceptions.OutOfRangeDateError: The date must be between 1899-07-29 and 2053-10-07183 - The date given in parameter is considered as being given from the point of view of the given timezone.184 Using a timezone that does not correspond to the place's actual one can impact the returned times.185 """186 def get_angle(for_aster: Object):187 def fun(time: Time) -> float:188 return (189 position.get_planet_topos()190 .at(time)191 .observe(for_aster.skyfield_object)192 .apparent()193 .altaz()[0]194 .degrees195 )196 fun.rough_period = 1.0197 return fun198 def is_risen(for_aster: Object):199 def fun(time: Time) -> bool:200 return get_angle(for_aster)(time) > RISEN_ANGLE201 fun.rough_period = 0.5202 return fun203 # The date given in argument is supposed to be given in the given timezone (more natural for a human),204 # but we need it in UTC. Subtracting the timezone to get it in UTC.205 start_time = get_timescale().utc(206 for_date.year, for_date.month, for_date.day, -timezone207 )208 end_time = get_timescale().utc(209 for_date.year, for_date.month, for_date.day + 1, -timezone210 )211 ephemerides = []212 try:213 for aster in ASTERS:214 times, risen_info = find_discrete(start_time, end_time, is_risen(aster))215 culmination_time, _ = find_maxima(start_time, end_time, get_angle(aster))216 rise_time, set_time = None, None217 culmination_time = (218 culmination_time[0] if len(culmination_time) == 1 else None219 )220 for i, time in enumerate(times):221 time_dt = normalize_datetime(222 translate_to_timezone(time.utc_datetime(), to_tz=timezone)223 )224 if time_dt is not None and time_dt.day != for_date.day:225 continue226 if risen_info[i]:227 rise_time = time_dt228 else:229 set_time = time_dt230 if culmination_time is not None:231 culmination_time = normalize_datetime(232 translate_to_timezone(233 culmination_time.utc_datetime(),234 to_tz=timezone,235 )236 )237 ephemerides.append(238 AsterEphemerides(rise_time, culmination_time, set_time, aster=aster)239 )240 except EphemerisRangeError as error:241 start = translate_to_timezone(error.start_time.utc_datetime(), timezone)242 end = translate_to_timezone(error.end_time.utc_datetime(), timezone)243 start = date(start.year, start.month, start.day + 1)244 end = date(end.year, end.month, end.day - 1)245 raise OutOfRangeDateError(start, end) from error...
NoCopHH_mod_functions.py
Source:NoCopHH_mod_functions.py
1import pyomo.environ as py2def return_time_series_and_constants(file):3 _time_series = file["Time series"].set_index("Time")4 _constants = file["Constants"]5 # scenario analysis6 return _time_series, _constants7def init_spot(m, t):8 return m.time["Spot"][t]9def init_gen(m, t):10 return m.time["Generation"][t]11def init_load(m, t):12 return m.time["Load"][t]13def init_fossil(m, t):14 return m.time["Fossil"][t]15def init_co2(m, t):16 return m.time["CO2"][t]17def create_and_initialize_the_model(time, con):18 m = py.ConcreteModel()19 m.set_time = py.Set(initialize=time.index)20 m.time = time21 m.con = con22 # add time series data to framework23 m.ts_spot = py.Param(m.set_time, initialize=init_spot)24 m.ts_gen = py.Param(m.set_time, initialize=init_gen)25 m.ts_load = py.Param(m.set_time, initialize=init_load)26 m.ts_fossil = py.Param(m.set_time, initialize=init_fossil)27 m.ts_CO2 = py.Param(m.set_time, initialize=init_co2)28 # add constants/parameters to framework29 m.c_future = py.Param(initialize=con["Future"][0])30 m.c_base = py.Param(initialize=con["Base"][0])31 m.c_alpha_fossil = py.Param(initialize=con["Alpha_fossil"][0])32 m.big_M = py.Param(initialize=10e7)33 return m34def add_decision_variables(m):35 # upper level36 # Implicit definition of inequality constraint (G1)37 m.v_q_spot = py.Var(m.set_time, domain=py.NonNegativeReals)38 # Implicit definition of inequality constraint (G2)39 m.v_q_future = py.Var(m.set_time, domain=py.NonNegativeReals)40 # Implicit definition of inequality constraint (G3)41 m.v_q_curtail = py.Var(m.set_time, domain=py.NonNegativeReals)42 # Implicit definition of inequality constraint (g2)43 m.v_p_H2 = py.Var(m.set_time, domain=py.NonNegativeReals)44 m.v_H2_snake = py.Var(domain=py.NonNegativeReals)45 m.v_future_snake = py.Var(domain=py.NonNegativeReals)46 # lower level (primal)47 m.v_q_fossil = py.Var(m.set_time, domain=py.NonNegativeReals)48 m.v_q_H2 = py.Var(m.set_time, domain=py.NonNegativeReals)49 m.v_q_CO2 = py.Var(m.set_time, domain=py.NonNegativeReals)50 # lower level (dual)51 # equality constraints (lambda)52 m.dual_lambda_load = py.Var(m.set_time)53 m.dual_lambda_CO2 = py.Var(m.set_time)54 # inequality constraints (mhu)55 m.dual_mhu_fossil = py.Var(m.set_time, domain=py.NonNegativeReals)56 m.dual_mhu_H2 = py.Var(m.set_time, domain=py.NonNegativeReals)57 m.dual_mhu_CO2 = py.Var(m.set_time, domain=py.NonNegativeReals)58 # Big M method (binary variables)59 m.u_fossil = py.Var(m.set_time, domain=py.Binary)60 m.u_H2 = py.Var(m.set_time, domain=py.Binary)61 m.u_CO2 = py.Var(m.set_time, domain=py.Binary)62 # add cost types63 m.revenues_spot = py.Var()64 m.revenues_future = py.Var()65 m.revenues_H2 = py.Var()66 return m67def revenues_spot(m):68 _revenues = 069 for t in m.set_time:70 _revenues += m.v_q_spot[t] * m.ts_spot[t]71 return _revenues == m.revenues_spot72def revenues_future(m):73 _revenues = 074 for t in m.set_time:75 _revenues += m.v_q_future[t] * m.c_future76 return _revenues == m.revenues_future77def revenues_hydrogen(m):78 return m.revenues_H2 == -sum(79 m.dual_lambda_load[t] * m.ts_load[t]80 + m.v_q_fossil[t] * m.ts_fossil[t]81 + m.v_q_CO2[t] * m.ts_CO2[t]82 for t in m.set_time83 )84def objective_function_maximize_revenues(m):85 return m.revenues_spot + m.revenues_future + m.revenues_H286def add_objective_function(m):87 m.rev_spot = py.Constraint(rule=revenues_spot)88 m.rev_future = py.Constraint(rule=revenues_future)89 m.rev_hydrogen = py.Constraint(rule=revenues_hydrogen)90 m.objective = py.Objective(91 expr=objective_function_maximize_revenues(m), sense=py.maximize92 )...
date_and_time.py
Source:date_and_time.py
1import datetime2# date related3dt = datetime.datetime4dt_now = dt.now()5dt_today = dt.today()6set_date = dt(1978, 1, 26, 1, 25, 00, 0000)7day, month, year = dt_today.day, dt_today.month, dt_today.year8# time related9d_time = datetime.time()10set_time = datetime.time(11, 24, 33)11# sritptime()12# strftime()13# timestamp()14print("today is,", dt_now)15print("now is,", dt_today)16print("current year is,", dt_now.year)17print("I was born on,", set_date)18print('{}.{}.{}.'.format(day, month, year))19print(d_time)20print("set time is,", set_time)21# backslash "\" for splitting long line of code for readability22print("hour = {}, minute = {}, secede = {}, microsecond = {}" \...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!