text
stringlengths
185
73.3k
repo
stringlengths
7
100
path
stringlengths
4
146
language
stringclasses
7 values
hash
stringlengths
16
16
score
float64
7
8.5
stars
int64
0
237k
""" Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is co...
kantarcise/notebook
Leet_Code/easy/141_Linked_List_Cycle.py
.py
1f0bced30f421f12
7.48
8
""" Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring). The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring. Example 1: Input: s ...
kantarcise/notebook
Leet_Code/easy/1422_Maximum_Score_After_Splitting_a_String.py
.py
f513225fc1f5ac56
7.48
8
""" You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city, that is, the city without any path outgoing to another city. It is guaranteed that the graph of paths forms a line without any loop, therefore, there will b...
kantarcise/notebook
Leet_Code/easy/1436_Destination_City.py
.py
f8da4393dd0f020b
7.48
8
""" Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1). Example 1: Input: nums = [3,4,5,2] Output: 12 Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1...
kantarcise/notebook
Leet_Code/easy/1464_Maximum_Product of_Two_Elements_in_an_Array.py
.py
0706a1911d5816a3
7.48
8
""" Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: strs = ["flower","flow","flight"] Output: "fl" Example 2: Input: strs = ["dog","racecar","car"] Output: "" Explan...
kantarcise/notebook
Leet_Code/easy/14_Longest_Common_Prefix.py
.py
125744129300489d
7.48
8
""" Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j. Example 1: Input: nums = [1,2,3,1,1,3] Output: 4 Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed. Example 2: Input: nums = [1,1,1,1] Output: 6 Explanation...
kantarcise/notebook
Leet_Code/easy/1512_Number_of_Good_Pairs.py
.py
44702d147672fe64
7.48
8
""" Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: 0 <= i <= s.length - 2 s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa. To make the string good, yo...
kantarcise/notebook
Leet_Code/easy/1544_Make_The_String_Great.py
.py
a04e6aaf1a8b1e9d
7.48
8
""" Given an integer n, add a dot (".") as the thousands separator and return it in string format. Example 1: Input: n = 987 Output: "987" Example 2: Input: n = 1234 Output: "1.234" Constraints: 0 <= n <= 2^31 - 1 """ from collections import deque class Solution: def thousandSepa...
kantarcise/notebook
Leet_Code/easy/1556_Thousand_Separator.py
.py
b067de0f6a70a5ec
7.48
8
""" Given an m x n binary matrix mat, return the number of special positions in mat. A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed). Example 1: Input: mat = [[1,0,0],[0,0,1],[1,0,0]] Output: 1 Explanation: (1, 2) is a speci...
kantarcise/notebook
Leet_Code/easy/1582_Special_Positions_in_a_Binary_Matrix.py
.py
b573d2f1208757c6
7.98
8
""" A string is a valid parentheses string (denoted VPS) if it meets one of the following: It is an empty string "", or a single character not equal to "(" or ")", It can be written as AB (A concatenated with B), where A and B are VPS's, or It can be written as (A), where A is a VPS. We can similarly define the nest...
kantarcise/notebook
Leet_Code/easy/1614_Maximum_Nesting_Depth_of_the_Parentheses.py
.py
918cb7e425f31a43
7.48
8
""" Given a string s, return the length of the longest substring between two equal characters, excluding the two characters. If there is no such substring return -1. A substring is a contiguous sequence of characters within a string. Example 1: Input: s = "aa" Output: 0 Explanation: The optimal substring here is a...
kantarcise/notebook
Leet_Code/easy/1624_Largest_Substring_Between_Two_Equal_Characters.py
.py
4f3923a0e96b0d7d
7.48
8
""" You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al". The interpreted strings are then concatenated in the original orde...
kantarcise/notebook
Leet_Code/easy/1678_Goal_Parser_Interpretation.py
.py
94da955533e60e7b
7.48
8
""" Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] Output: 2 Constraint...
kantarcise/notebook
Leet_Code/easy/169_majority_element.py
.py
47c9a37fae7c724f
7.48
8
""" You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half. Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase lette...
kantarcise/notebook
Leet_Code/easy/1704_Determine_if_String_Halves_Are_Alike.py
.py
0bbadf74aab90744
7.48
8
""" There is a hidden integer array arr that consists of n non-negative integers. It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3]. You are given the encoded array. You are also given an intege...
kantarcise/notebook
Leet_Code/easy/1720_Decode_XORed_Array.py
.py
1139c759402dae86
7.48
8
""" You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa. The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not. Return the minimum number...
kantarcise/notebook
Leet_Code/easy/1758_Minimum_Changes_To_Make_Alternating_Binary_String.py
.py
e311f1771df376fe
7.48
8
""" You are given an array of strings words (0-indexed). In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j]. Return true if you can make every string in words equal using any number of operations, and false oth...
kantarcise/notebook
Leet_Code/easy/1897_Redistribute_Characters_to_Make_All_Strings_Equal.py
.py
8b8f5a4013090d15
7.48
8
""" The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d). For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16. Given an integer array nums, choose four distinct indices w, x, y, and z such that the product difference between pairs (nums[w], nu...
kantarcise/notebook
Leet_Code/easy/1913_Maximum_Product_Difference_Between_Two_Pairs.py
.py
8772d0f0ab53b3a7
7.48
8
""" Write a function that takes the binary representation of a positive integer and returns the number of set bits it has (also known as the Hamming weight). Example 1: Input: n = 11 Output: 3 Explanation: The input binary string 1011 has a total of three set bits. Example 2: Input: n = ...
kantarcise/notebook
Leet_Code/easy/191_Number_of_1_Bits.py
.py
e7433b49db95a4a7
7.48
8
""" Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example 1: Input: nums = [2,7,11,15...
kantarcise/notebook
Leet_Code/easy/1_Two_Sum.py
.py
8915f890407d79b9
7.48
8
""" Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing. For example, if word = "abcdefd" and ch = "d", then you should reverse the segment that...
kantarcise/notebook
Leet_Code/easy/2000_Reverse_Prefix_of_Word.py
.py
1d16260967315be7
7.48
8
""" There is a programming language with only four operations and one variable X: ++X and X++ increments the value of the variable X by 1. --X and X-- decrements the value of the variable X by 1. Initially, the value of X is 0. Given an array of strings operations containing a list of operations, return the final va...
kantarcise/notebook
Leet_Code/easy/2011_Final_Value_of_Variable_After_Performing_Operations.py
.py
fa6136a6ab786d12
7.48
8
""" Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (where it will...
kantarcise/notebook
Leet_Code/easy/202_Happy_Number.py
.py
a6a06062d96c17ae
7.48
8
""" There are n seats and n students in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of the jth student. You may perform the following move any number of times: Increase or dec...
kantarcise/notebook
Leet_Code/easy/2037_Minimum_Number_of_Moves_to_Seat_Everyone.py
.py
d75c9ef7f5dd326c
7.48
8
""" Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, bu...
kantarcise/notebook
Leet_Code/easy/205_Isomorphic_Strings.py
.py
f7dd9a0c18108681
7.48
8
""" Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] Constraints: The number of nodes in the list is the range [0, 5000]. -500...
kantarcise/notebook
Leet_Code/easy/206_Reverse_Linked_List.py
.py
0a2db5439278d107
7.48
8
""" There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed integer array tickets of length n where the number of tickets that the ith person would like to buy is tickets[i]. Each person ta...
kantarcise/notebook
Leet_Code/easy/2073_Time_Needed_to_Buy_Tickets.py
.py
3514c3213cc99fda
7.48
8
""" A sentence is a list of words that are separated by a single space with no leading or trailing spaces. You are given an array of strings sentences, where each sentences[i] represents a single sentence. Return the maximum number of words that appear in a single sentence. Example 1: Input: sentences = ["alice ...
kantarcise/notebook
Leet_Code/easy/2114_Maximum_Number_of_Words_Found_in_Sentences.py
.py
16110266e3f540fd
7.48
8
""" A string s can be partitioned into groups of size k using the following procedure: The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, and so on. Each character can be a part of exactly one group. For the last group, if the strin...
kantarcise/notebook
Leet_Code/easy/2138_Divide_a_String_Into_Groups_of_Size_k.py
.py
bfb5f73d5868712a
7.48
8
""" Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k. Example 1: Input: nums = [1,2,3,1], k = 3 Output: true Example 2: Input: nums = [1,0,1,1], k = 1 Output: true Example 3: Input: nums = [1,2,3,1,...
kantarcise/notebook
Leet_Code/easy/219_Contains_Duplicate_II.py
.py
d80f8f46196b055c
7.48
8
from datetime import datetime, timezone import boto3 from cloud_governance.cloud_resource_orchestration.clouds.aws.ec2.collect_cro_reports import CollectCROReports from cloud_governance.cloud_resource_orchestration.clouds.aws.ec2.cost_over_usage import CostOverUsage from cloud_governance.cloud_resource_orchestration....
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/run_cro.py
.py
26b0f4cf61dd7e59
7.64
18
import boto3 import typeguard from cloud_governance.common.clouds.aws.ec2.ec2_operations import EC2Operations from cloud_governance.common.jira.jira_operations import JiraOperations from cloud_governance.common.ldap.ldap_search import LdapSearch from cloud_governance.common.logger.init_logger import logger from cloud_...
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/tag_cro_instances.py
.py
4d73eddcbe1024c1
7.64
18
import json import tempfile from abc import ABC from datetime import datetime import typeguard from cloud_governance.cloud_resource_orchestration.clouds.aws.ec2.aws_tagging_operations import AWSTaggingOperations from cloud_governance.cloud_resource_orchestration.common.abstract_monitor_tickets import AbstractMonito...
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/clouds/azure/resource_groups/azure_monitor_tickets.py
.py
1836ed357ca8fec2
7.64
18
import typeguard from cloud_governance.cloud_resource_orchestration.clouds.common.abstract_tagging_operations import \ AbstractTaggingOperations from cloud_governance.common.clouds.azure.compute.resource_group_operations import ResourceGroupOperations from cloud_governance.common.logger.logger_time_stamp import ...
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/clouds/azure/resource_groups/azure_tagging_operations.py
.py
065500536636f4ad
7.64
18
import logging from abc import ABC from datetime import datetime, timedelta, timezone import typeguard from cloud_governance.cloud_resource_orchestration.clouds.aws.ec2.cost_over_usage import CostOverUsage from cloud_governance.common.clouds.aws.iam.iam_operations import IAMOperations from cloud_governance.common.ela...
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/clouds/common/abstract_collect_cro_reports.py
.py
d78ec2ca2156965a
7.64
18
from abc import ABC, abstractmethod class AbstractTaggingOperations(ABC): """ This class is abstract tagging operations to all the clouds """ def __init__(self): super().__init__() @abstractmethod def get_resources_list(self, tag_name: str, tag_value: str = ''): raise NotImpl...
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/clouds/common/abstract_tagging_operations.py
.py
196c9d76b9ce940a
7.14
18
from cloud_governance.cloud_resource_orchestration.common.run_cro import RunCRO from cloud_governance.common.jira.jira import logger from cloud_governance.common.logger.logger_time_stamp import logger_time_stamp from cloud_governance.main.environment_variables import environment_variables class CloudMonitor: """ ...
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/monitor/cloud_monitor.py
.py
78b510a908e1d095
7.64
18
import re from datetime import datetime from typing import Union from cloud_governance.main.environment_variables import environment_variables _ISO_DATETIME_OFFSET_RE = re.compile(r'[+-]\d{2}:\d{2}$') def parse_iso_datetime(value: str) -> datetime: """ This method parses an ISO 8601 datetime string, tolerat...
redhat-performance/cloud-governance
cloud_governance/cloud_resource_orchestration/utils/common_operations.py
.py
a0ee5bad70e520aa
7.64
18
from abc import ABC, abstractmethod from datetime import datetime, timezone from cloud_governance.main.environment_variables import environment_variables class AbstractAthenaOperations(ABC): CURRENT_DATE = str(datetime.now(tz=timezone.utc).date()).replace("-", "") def __init__(self): self.__environ...
redhat-performance/cloud-governance
cloud_governance/common/clouds/aws/athena/abstract_athena_operations.py
.py
e7f80dc6f49d4fa6
7.64
18
import boto3 import typeguard from cloud_governance.common.clouds.aws.athena.abstract_athena_operations import AbstractAthenaOperations from cloud_governance.common.logger.init_logger import logger from cloud_governance.common.logger.logger_time_stamp import logger_time_stamp class BotoClientAthenaOperations(Abstrac...
redhat-performance/cloud-governance
cloud_governance/common/clouds/aws/athena/boto3_client_athena_operations.py
.py
87885da42d58bef8
7.64
18
# infections.py # # A utility that provides a list of infections (forced internal errors). # Infections are injected into the application via the environment variable # 'INFECTIONS', a comma-separated list of infection names. from typing import Dict, Set from django.conf import settings from api.utils import deploym...
xchem/fragalysis-backend
api/infections.py
.py
2a01b7463a36ae22
7.45
7
# pylint: skip-file import logging import os from dataclasses import dataclass from pathlib import Path from typing import Any, Dict, Optional from wsgiref.util import FileWrapper import ta_auth_connector from django.conf import settings from django.contrib.auth import get_user_model from django.db.models import Q fro...
xchem/fragalysis-backend
api/security.py
.py
d4c09da88273a767
7.45
7
import re import xml.etree.ElementTree as ET from typing import Optional, Tuple from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist from django.http import HttpResponse from fragutils.utils.network_utils import canon_input from rdkit import...
xchem/fragalysis-backend
api/utils.py
.py
d37d874da9f4dc1d
7.45
7
"""Classes to override default OIDCAuthenticationBackend (Keycloak authentication) """ import logging from django.conf import settings from django.db import IntegrityError, transaction from mozilla_django_oidc.auth import OIDCAuthenticationBackend from requests.exceptions import HTTPError from rest_framework.exception...
xchem/fragalysis-backend
fragalysis/auth.py
.py
79b567d75855fda5
7.45
7
# Classes/Methods to override default OIDC Views (Keycloak authentication) from django.conf import settings from django.http import JsonResponse from mozilla_django_oidc.views import OIDCLogoutView def keycloak_logout(request): """Ths method is used to retrieve logout endpoint to also end the keycloak session as ...
xchem/fragalysis-backend
fragalysis/views.py
.py
6d33f3a49860e26c
7.45
7
from django.db import models from viewer.models import SiteObservation, Target class HotspotMap(models.Model): """ Django model for Hotspot Maps """ # The site # prot_id = models.ForeignKey(Protein, on_delete=models.CASCADE) site_observation = models.ForeignKey(SiteObservation, on_delete=mod...
xchem/fragalysis-backend
hotspots/models.py
.py
9d1584f5439640be
7.45
7
from django.db import models from hypothesis.definitions import IntTypes, VectTypes from viewer.models import Compound, SiteObservation, Target class TargetResidue(models.Model): """Model to store residue information - to curate the probes""" # The target it relates to target_id = models.ForeignKey(Targ...
xchem/fragalysis-backend
hypothesis/models.py
.py
24d95ab955017122
7.45
7
from contextlib import contextmanager from datetime import datetime, timedelta, timezone from typing import Any, Generator, Mapping, MutableMapping from uuid import uuid4 from blinker import ANY from flask import Flask, Request, current_app from flask import session as cookie_session from flask_login import LoginManag...
ONSdigital/eq-questionnaire-runner
app/authentication/authenticator.py
.py
d99f9b742ecf5156
7.52
10
from datetime import datetime, timedelta from flask import current_app from structlog import get_logger from app.data_models.app_models import UsedJtiClaim from app.helpers.uuid_helper import is_valid_uuid4 from app.storage.errors import ItemAlreadyExistsError logger = get_logger() class JtiTokenUsed(Exception): ...
ONSdigital/eq-questionnaire-runner
app/authentication/jti_claim_storage.py
.py
973fe1836650bf64
7.52
10
from __future__ import annotations from typing import Iterable, Iterator from app.data_models.answer import Answer, AnswerDict AnswerKeyType = tuple[str, str | None] class AnswerStore: """ An object that stores and updates a collection of answers, ready for serialisation via the Questionnaire Store. ...
ONSdigital/eq-questionnaire-runner
app/data_models/answer_store.py
.py
1e3926416e9e8980
7.52
10
from typing import Iterable, MutableMapping from app.data_models.progress import CompletionStatus, Progress, ProgressDict from app.questionnaire.location import Location, SectionKey from app.utilities.types import LocationType class ProgressStore: """ An object that stores and updates references to sections ...
ONSdigital/eq-questionnaire-runner
app/data_models/progress_store.py
.py
e7ff2919a379d42c
7.52
10
from dataclasses import asdict, dataclass from typing import Iterable, Iterator, TypedDict, cast class RelationshipDict(TypedDict, total=False): list_item_id: str to_list_item_id: str relationship: str @dataclass class Relationship: """ Represents a relationship between two items. """ l...
ONSdigital/eq-questionnaire-runner
app/data_models/relationship_store.py
.py
505ad949a614f226
7.52
10
from __future__ import annotations from datetime import datetime from flask import current_app from jwcrypto.common import base64url_decode from structlog import get_logger from app.data_models.app_models import EQSession from app.data_models.session_data import SessionData from app.storage.storage_encryption import...
ONSdigital/eq-questionnaire-runner
app/data_models/session_store.py
.py
c9d48a8e994b9181
7.52
10
from __future__ import annotations from functools import cached_property from typing import Iterable, Mapping, MutableMapping from werkzeug.datastructures import ImmutableDict from app.utilities.make_immutable import make_immutable from app.utilities.types import ( SupplementaryDataKeyType, SupplementaryData...
ONSdigital/eq-questionnaire-runner
app/data_models/supplementary_data_store.py
.py
63abd3d9d862aec4
7.52
10
from typing import Any, Sequence from wtforms.fields.core import UnboundField from app.forms.field_handlers.field_handler import FieldHandler from app.forms.fields import ( MultipleSelectFieldWithDetailAnswer, SelectFieldWithDetailAnswer, ) from app.questionnaire.dynamic_answer_options import DynamicAnswerOpt...
ONSdigital/eq-questionnaire-runner
app/forms/field_handlers/select_handlers.py
.py
b2e87491eb1dbae9
7.52
10
from decimal import Decimal, InvalidOperation from typing import Any, Sequence from wtforms import DecimalField from app.helpers.form_helpers import sanitise_number class DecimalFieldWithSeparator(DecimalField): """ The default wtforms field coerces data to an number and raises cast errors outside of it...
ONSdigital/eq-questionnaire-runner
app/forms/fields/decimal_field_with_separator.py
.py
57a3b6535438e051
7.52
10
from typing import Any, Sequence from wtforms import IntegerField from app.helpers.form_helpers import sanitise_number class IntegerFieldWithSeparator(IntegerField): """ The default wtforms field coerces data to an int and raises cast errors outside of it's validation chain. In order to stop the val...
ONSdigital/eq-questionnaire-runner
app/forms/fields/integer_field_with_separator.py
.py
c2e44558799af804
7.52
10
""" Read from a geo raster the heights for sites using UTM coordinates """ import sys import rasterio as rio from odmf import db from odmf.tools import Path as OPath class RasterReader: """ A simple wrapper for raster data for easy access of data Usage: >>>dem = RasterReader('test.tif') >>>print...
jlu-ilr-hydro/odmf
bin/demreader.py
.py
873753fb039691c7
7.42
6
""" Imports a PostgreSQL dump into sqlite db for test puroposes 1) make a new odmf instance with `odmf configure` / `odmf db-create` 2) In an interactive session with the source instance run `export_all_tables` to create parquet files for each table 3) """ import pandas as pd from odmf import db from pathlib import P...
jlu-ilr-hydro/odmf
bin/psql2sqlite.py
.py
fb58f2e56457e3c1
7.42
6
import tables import pandas as pd from odmf import db from sqlalchemy.types import JSON from sqlalchemy.sql.selectable import Select import time from typing import Optional def now(ago=None): if ago is None: return pd.to_datetime('now') else: ago = pd.to_timedelta(ago) return pd.to_dat...
jlu-ilr-hydro/odmf
bin/to_hdf.py
.py
a275823aed3ad9c6
7.42
6
# Parse conf.py in the root directory and check for validity # # A more detailed explanation of a valid configuration can be found # in the documentation # import yaml from pathlib import Path import sys import os from logging import getLogger from . import prefix, __version__ logger = getLogger(__name__) class C...
jlu-ilr-hydro/odmf
odmf/config.py
.py
33875d09e02d2528
7.42
6
""" Reads a table with lab data using a configuration file (in yaml format) Example config file: """ import typing import pandas as pd from .. import db from ..tools import Path from .parquet_import import addrecords_dataframe from .sample_parser import SampleParser import yaml example=r""" driver: read_excel # pan...
jlu-ilr-hydro/odmf
odmf/dataimport/lab_import.py
.py
754e693cbaff9451
7.42
6
from .base import ImportDescription, ImportColumn import typing from .. import db import pandas as pd import re import datetime from ..config import conf from odmf.tools import Path from logging import getLogger logger = getLogger(__name__) class DataImportError(RuntimeError): ... class ColumnDataset: """ ...
jlu-ilr-hydro/odmf
odmf/dataimport/pandas_import.py
.py
1034247500ab1387
7.42
6
#!/usr/bin/env python3 """ Imports parquet file in the record table format into the database, perfoming a couple of checks Philipp Kraft 2022-06-23 """ import logging import pandas as pd from odmf import db logger = logging.getLogger(__name__) def _adjust_columns(df: pd.DataFrame): """ Adds and removes colu...
jlu-ilr-hydro/odmf
odmf/dataimport/parquet_import.py
.py
4cbe6f5bd20f2223
7.42
6
import re from datetime import datetime """ Tools to parse sample names into sites, datasets, datetime values etc. The parser is defined using a yml file. Example: """ example = r""" pattern: (\w+?)_([0-9\.]+_[0-9]+\:[0-9]+)_?([\-\+]?[0-9\.]+)? site: group: 1 map: F1: 137 F2: 147 F3: 201 B1: 123 ...
jlu-ilr-hydro/odmf
odmf/dataimport/sample_parser.py
.py
1df39f5489266071
7.42
6
import sqlalchemy as sql import sqlalchemy.orm as orm from datetime import datetime from base64 import b64encode from io import BytesIO from PIL import Image as pil from .base import Base from ..tools.migrate_db import new_column from logging import getLogger logger = getLogger(__name__) class Image(Base): __tabl...
jlu-ilr-hydro/odmf
odmf/db/image.py
.py
1954019cbb7a5770
7.42
6
import sqlalchemy as sql import sqlalchemy.orm as orm from datetime import datetime, timedelta from traceback import format_exc as traceback from functools import total_ordering from itertools import chain from sqlalchemy import ForeignKey from sqlalchemy_json import NestedMutableJson from typing import Optional, Lis...
jlu-ilr-hydro/odmf
odmf/db/message.py
.py
0584156ad311a044
7.42
6
import sqlalchemy as sql import sqlalchemy.orm as orm from datetime import datetime, timedelta import typing import numpy as np import pandas as pd from dataclasses import dataclass from .base import Base, newid from .dataset import Dataset from logging import getLogger from .message import Topic logger = getLogger(...
jlu-ilr-hydro/odmf
odmf/db/timeseries.py
.py
d0241eabbd43ef79
7.42
6
""" A backend to create plots with matplotlib Each backend needs to implement the function to_image(plot, format, dpi) and to_html(plot). """ import datetime import io from matplotlib.figure import Axes, Figure from matplotlib.ticker import MaxNLocator from matplotlib import pyplot as plt import numpy as np from .pl...
jlu-ilr-hydro/odmf
odmf/plot/draw_mpl.py
.py
6117dc2300dd3d14
7.42
6
""" Calculates a summary table for a specific timespan, starting from the latest date """ import typing import datetime import numpy as np import pandas as pd from .. import db def summarize_item( session, timespan: typing.Optional[pd.Timedelta]=None, aggregate: str='mean', name:str = '', ...
jlu-ilr-hydro/odmf
odmf/plot/summary_table.py
.py
71f6a5e40e36b7b7
7.42
6
from glob import glob import os import os.path as op import typing import bcrypt from ..config import conf import pathlib from contextlib import contextmanager __all__ = ['mail', 'Path'] class Path: def __init__(self, *path: str|typing.Self|pathlib.Path, absolute=False): self.datapath = op.realpath(conf....
jlu-ilr-hydro/odmf
odmf/tools/__init__.py
.py
6c99681774fd3e54
7.42
6
import re import pandas as pd def parse_access_log(fn='access.log'): """ Reads the access log and returns a dataframe :param fn: :return: """ pattern = re.compile(r'([0-9\.]*) - (.*?) \[(.*?)\] \"(.*?)\" ([0-9]*) ([0-9\-]*) \"(.*?)\" \"(.*?)\"') names = 'ip','user','date','request','status...
jlu-ilr-hydro/odmf
odmf/tools/check_login_time.py
.py
8b375c27a7cbd9c6
7.42
6
from getpass import getpass import logging import sys from typing import List logger = logging.getLogger(__name__) from .migrate_db import migrate as migrate_db def create_all_tables() -> List[str]: """ Creates all database table necessary for the database from the codebase :return: A list of """ ...
jlu-ilr-hydro/odmf
odmf/tools/create_db.py
.py
f07e6afae591829d
7.42
6
''' Exports the climate datasets as one table with multiple columns Created on 05.06.2013 @author: kraft-p ''' import pandas as pd import typing import datetime class DecadeMonthStart(pd._libs.tslibs.offsets.BaseOffset): # noqa """ A try to use decades as resample periods, based on this pandas question: ...
jlu-ilr-hydro/odmf
odmf/tools/exportdatasets.py
.py
aa24a39989e61e6f
7.42
6
""" This module provides functions to bulk import database objects from tabular data. Mainly for sites and datasets, but eventually more like Users, Instruments, etc. """ import typing import pandas as pd import geopandas as gpd from shapely import to_geojson from pathlib import Path import yaml from .. import db f...
jlu-ilr-hydro/odmf
odmf/tools/import_objects.py
.py
bb47cec4248c409d
7.42
6
""" A mail daemon thread. Runs together with the website and sends messages when they are due. """ import typing from datetime import datetime, timedelta from threading import Timer import logging from odmf.config import conf from odmf.db import session_scope, Job, sql, flex_get, newid from odmf.db.message import Mes...
jlu-ilr-hydro/odmf
odmf/tools/mail/maildaemon.py
.py
9124ddb93cf24d78
7.42
6
# # Copyright (C) 2019 CERN. # # inspirehep is free software; you can redistribute it and/or modify it under # the terms of the MIT License; see LICENSE file for more details. import structlog from flask import current_app from flask_login import current_user from inspire_schemas.api import load_schema from inspire_u...
inspirehep/inspirehep
backend/inspirehep/accounts/api.py
.py
18fe11497ffcb00b
7.66
20
# # Copyright (C) 2019 CERN. # # inspirehep is free software; you can redistribute it and/or modify it under # the terms of the MIT License; see LICENSE file for more details. from functools import wraps from flask import abort from flask_login import current_user from inspirehep.accounts.roles import Roles def log...
inspirehep/inspirehep
backend/inspirehep/accounts/decorators.py
.py
be8fd98763dd4e43
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Drop CDS Table""" import sqlalchemy as sa from alembic import op from sqlalchemy_utils import UUIDType #...
inspirehep/inspirehep
backend/inspirehep/alembic/00e051bc08b2_drop_cds_table.py
.py
c973a530093adef1
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Add index to records authors table""" from alembic import op # revision identifiers, used by Alembic. re...
inspirehep/inspirehep
backend/inspirehep/alembic/020b99d0beb7_add_index_to_records_authors_table.py
.py
fff58045015ef705
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """add workflow_record_sources table""" import sqlalchemy as sa from alembic import op from sqlalchemy.diale...
inspirehep/inspirehep
backend/inspirehep/alembic/0ae62076ae0c_add_workflow_record_sources_table.py
.py
ce5718cf98526358
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """add journal_literature table""" import sqlalchemy as sa from alembic import op from sqlalchemy_utils.type...
inspirehep/inspirehep
backend/inspirehep/alembic/0d1cf7c4501e_add_journal_literature_table.py
.py
5625c92888fba21e
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """add students_advisors table""" import sqlalchemy as sa from alembic import op from sqlalchemy.dialects im...
inspirehep/inspirehep
backend/inspirehep/alembic/232af38d2604_add_students_advisors_table.py
.py
22e6662593df1d6b
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """add index to authors_records""" from alembic import op # revision identifiers, used by Alembic. revision...
inspirehep/inspirehep
backend/inspirehep/alembic/2d7ea622feda_add_index_to_authors_records.py
.py
47729478451190e9
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """modify idx_object index in pidstore_pid table""" from alembic import op # revision identifiers, used by ...
inspirehep/inspirehep
backend/inspirehep/alembic/318758a589d5_modify_idx_object_index_in_pidstore_pid_.py
.py
008e1bdc37ca2e95
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """update primary key in students advisors""" import sqlalchemy as sa from alembic import op # revision ide...
inspirehep/inspirehep
backend/inspirehep/alembic/35ba3d715114_update_primary_key_in_students_advisors.py
.py
f576c421acdd2809
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """update values in AuthorSchemaType""" from alembic import op # revision identifiers, used by Alembic. rev...
inspirehep/inspirehep
backend/inspirehep/alembic/3637cb5551a8_update_values_in_authorschematype.py
.py
8be22261d0b39f6d
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """remove_legacy_records_mirror_table""" import sqlalchemy as sa from alembic import op from sqlalchemy.dial...
inspirehep/inspirehep
backend/inspirehep/alembic/3fd6471bb960_remove_legacy_records_mirror_table.py
.py
f7b33b44ba7cf47b
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Add CDSRun status model""" import sqlalchemy as sa from alembic import op from sqlalchemy_utils import UU...
inspirehep/inspirehep
backend/inspirehep/alembic/412aeb064d68_add_cdsrun_status_model.py
.py
f2c2402b9090fe3d
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Alter records_authors id to big_int""" import sqlalchemy as sa from alembic import op # revision identif...
inspirehep/inspirehep
backend/inspirehep/alembic/41e81f8ee63a_alter_records_authors_id_to_big_int.py
.py
cfc48038750e5a4c
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """add_inspire_redirection_table""" import sqlalchemy as sa from alembic import op revision = "49a436a179ac...
inspirehep/inspirehep
backend/inspirehep/alembic/49a436a179ac_add_inspire_redirection_table.py
.py
f2ce082cfd92753d
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Data collection citations""" import sqlalchemy as sa import sqlalchemy_utils from alembic import op # re...
inspirehep/inspirehep
backend/inspirehep/alembic/503b34c08b0b_data_collection_citations.py
.py
23623727f084aae1
7.66
20
# # Copyright (C) 2019 CERN. # # inspirehep is free software; you can redistribute it and/or modify it under # the terms of the MIT License; see LICENSE file for more details. """Add authors to records table and update index on records_citations""" import sqlalchemy as sa from alembic import op from inspirehep.record...
inspirehep/inspirehep
backend/inspirehep/alembic/595c36d68964_add_authors_to_records_table_and_update_.py
.py
2bbd4c70a07e5662
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Add is_self_citation column to citation_table""" import sqlalchemy as sa from alembic import op # revisi...
inspirehep/inspirehep
backend/inspirehep/alembic/5a0e2405b624_add_citation_type_to_citation_table.py
.py
6c380003127954cc
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Add lecacy_records_mirror table""" import sqlalchemy as sa from alembic import op # revision identifiers...
inspirehep/inspirehep
backend/inspirehep/alembic/5ce9ef759ace_add_lecacy_records_mirror_table.py
.py
1c8f85b8297f00ae
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """update constraints in records_authors""" from alembic import op # revision identifiers, used by Alembic....
inspirehep/inspirehep
backend/inspirehep/alembic/72d010d89702_update_constraints_in_records_authors.py
.py
364615d4da613e8c
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """remove pid_provider index from pidstore""" from alembic import op # revision identifiers, used by Alembi...
inspirehep/inspirehep
backend/inspirehep/alembic/788a3a61a635_remove_pid_provider_index_from_pidstore.py
.py
802d1af15fab8752
7.66
20
# # Copyright (C) 2019 CERN. # # inspirehep is free software; you can redistribute it and/or modify it under # the terms of the MIT License; see LICENSE file for more details. """Inspirehep initial revision of migrations which makes db identical like in inspire-next""" # revision identifiers, used by Alembic. revisio...
inspirehep/inspirehep
backend/inspirehep/alembic/7be4c8b5c5e8_inspirehep_new_migrations.py
.py
663cf8987cd25ef9
7.66
20
# # Copyright (C) 2019 CERN. # # inspirehep is free software; you can redistribute it and/or modify it under # the terms of the MIT License; see LICENSE file for more details. """Add indexed to records_citations on is_self_citation column""" from alembic import op revision = "8ba47044154a" down_revision = "5a0e2405b...
inspirehep/inspirehep
backend/inspirehep/alembic/8ba47044154a_add_indexed_to_records_citations_on_is_.py
.py
3b484309a0f701a4
7.66
20
# # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """add experiment_literature table""" import sqlalchemy as sa from alembic import op from sqlalchemy_utils....
inspirehep/inspirehep
backend/inspirehep/alembic/afe5f484abcc_add_experiments_literature_table.py
.py
e7c339cac0068fb7
7.66
20