python_code stringlengths 0 4.04M | repo_name stringlengths 7 58 | file_path stringlengths 5 147 |
|---|---|---|
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
import time
import hydra
import matplotlib.pyplot as plt
import pytorch_lightning as pl
import torch
from hydra.utils import get_original_cwd
from omegaconf import DictConfig, OmegaC... | collaborative_image_understanding-main | src/main_train_model_cf_based.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
import time
from glob import glob
import hydra
import numpy as np
import torch
from omegaconf import DictConfig, OmegaConf
from torch.utils.data.dataloader import DataLoader
from tqd... | collaborative_image_understanding-main | src/main_predict_testset.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
import time
import hydra
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder
from tqdm import tqdm
from main_proc... | collaborative_image_understanding-main | src/main_download_pinterest_sets.py |
# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
import logging
import os.path as osp
import time
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import torch
from torch.utils.data import Dataset
from torchvision import transforms
from torchvision.datasets.folder import defaul... | collaborative_image_understanding-main | src/dataset_utils.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
from typing import List
import pandas as pd
import requests
from tqdm import tqdm
logger = logging.getLogger(__name__)
class DataHelper:
def __init__(self, is_debug: bool, is_... | collaborative_image_understanding-main | src/data_utils.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
import time
from glob import glob
import hydra
import pandas as pd
import torch
from hydra.utils import get_original_cwd
from omegaconf import DictConfig, OmegaConf
from sklearn.metr... | collaborative_image_understanding-main | src/main_extract_embeddings.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import time
import os.path as osp
import hydra
import pytorch_lightning as pl
import torch
from hydra.utils import get_original_cwd
from omegaconf import DictConfig, OmegaConf
from pytorch_lightning import... | collaborative_image_understanding-main | src/train_model_with_cf_pretraining.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
import time
from itertools import chain
import hydra
import numpy as np
import pandas as pd
from omegaconf import DictConfig
from sklearn.model_selection import train_test_split
from... | collaborative_image_understanding-main | src/main_process_labels_movielens.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
import time
import cornac
import hydra
import pandas as pd
import torch
from cornac.eval_methods import RatioSplit
from cornac.metrics import AUC, MAP
from omegaconf import DictConfi... | collaborative_image_understanding-main | src/main_train_recommender.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os.path as osp
from typing import List
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import torch
from cornac.data import Reader
from cornac.models import VAECF
from cornac.models.re... | collaborative_image_understanding-main | src/recommender_utils.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import time
import hydra
import pytorch_lightning as pl
import torch
from hydra.utils import get_original_cwd
from omegaconf import DictConfig, OmegaConf
from pytorch_lightning import loggers as pl_logger... | collaborative_image_understanding-main | src/main_train_model.py |
# Copyright (c) 2015-present, Meta Platforms, Inc. and affiliates.
# All rights reserved.
import logging
import os
import os.path as osp
import hydra
import numpy as np
import pandas as pd
import scipy
from hydra.utils import get_original_cwd
from omegaconf import DictConfig, OmegaConf
from scipy.stats import ttest_re... | collaborative_image_understanding-main | src/eval_utils.py |
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law o... | Aria_data_tools-main | src/setup.py |
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law o... | Aria_data_tools-main | src/python/tutorials/DataProvider_ImageTimeline.py |
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law o... | Aria_data_tools-main | src/python/tutorials/Sensors.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import time
import json
import numpy as np
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
from ax.modelbri... | ContextualBO-main | park_abr/run_park_hesbo.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Run benchmarks for Ensemble BO.
Requires installing EBO from https://github.com/zi-w/Ensemble-Bayesian-Optimization.
"""
import os
import... | ContextualBO-main | park_abr/run_park_ebo.py |
#! /usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Dict, List
import numpy as np
import park
from ax.utils.common.logger import get_logger
NUM_RUNS... | ContextualBO-main | park_abr/fb_abr_problem.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Run benchmarks for Add-GP-UCB.
Requires installing dragonfly-opt from pip. The experiments here used version
0.1.4.
"""
import cma
impor... | ContextualBO-main | park_abr/run_park_add_ucb.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import time
import json
import numpy as np
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
from ax.modelbri... | ContextualBO-main | park_abr/run_park_rembo.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import time
import json
import numpy as np
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
from ax.modelbri... | ContextualBO-main | park_abr/run_park_sac.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Run benchmarks for CMAES.
Requires installing cma from pip. The experiments here used version 2.7.0.
"""
import cma
import time
import j... | ContextualBO-main | park_abr/run_park_cma_es.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import time
import json
import numpy as np
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
from ax.modelbri... | ContextualBO-main | park_abr/run_park_alebo.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import time
import json
import numpy as np
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
from ax.modelbri... | ContextualBO-main | park_abr/run_park_standard_bo.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import time
import json
import numpy as np
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
from ax.modelbri... | ContextualBO-main | park_abr/run_park_non_contextual.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import time
import json
import numpy as np
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
from ax.modelbri... | ContextualBO-main | park_abr/run_park_lcea.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Run benchmarks for TuRBO.
Requires installing turbo from https://github.com/uber-research/TuRBO.
"""
import turbo
import time
import jso... | ContextualBO-main | park_abr/run_park_turbo.py |
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Any, Dict, List, Optional, Type
import torch
from ax.core.data import Data
from ax.core.experiment ... | ContextualBO-main | park_abr/cbo_generation_strategy.py |
# Folk of the adaptive video streaming environment in https://github.com/park-project/park
from park.envs import make
| ContextualBO-main | park_abr/park/__init__.py |
# Folk of the adaptive video streaming environment in https://github.com/park-project/park
from park import logger
# Env-related abstractions
class Env(object):
"""
The main park class. The interface follows OpenAI gym
https://gym.openai.com, which encapsulates an environment with
arbitrary behind-th... | ContextualBO-main | park_abr/park/core.py |
# Folk of the adaptive video streaming environment in https://github.com/park-project/park
import logging
def debug(msg):
logging.debug(msg)
def info(msg):
logging.info(msg)
def warn(msg):
logging.warning(msg)
def error(msg):
logging.error(msg)
def exception(msg, *args, **kwargs):
logging... | ContextualBO-main | park_abr/park/logger.py |
import numpy as np
from park import core, logger
from park.spaces.rng import np_random
class Box(core.Space):
"""
A box in R^n.
I.e., each coordinate is bounded.
Example usage:
self.action_space = spaces.Box(low=-10, high=10, shape=(1,))
"""
def __init__(self, low=None, high=None, struct=... | ContextualBO-main | park_abr/park/spaces/box.py |
import numpy as np
"""
Separate the random number generator from the environment.
This is used for all random sample in the space native methods.
We expect new algorithms to have their own rngs.
"""
np_random = np.random.RandomState()
np_random.seed(42)
| ContextualBO-main | park_abr/park/spaces/rng.py |
import numpy as np
from park import core
from park.spaces.rng import np_random
class Discrete(core.Space):
"""
{0,1,...,n-1}
Example usage:
self.observation_space = spaces.Discrete(2)
"""
def __init__(self, n):
self.n = n
core.Space.__init__(self, "tensor_int64", (), np.int64)... | ContextualBO-main | park_abr/park/spaces/discrete.py |
from park.spaces.box import Box
from park.spaces.discrete import Discrete
| ContextualBO-main | park_abr/park/spaces/__init__.py |
import numpy as np
def np_random(seed=42):
if not (isinstance(seed, int) and seed >= 0):
raise ValueError("Seed must be a non-negative integer.")
rng = np.random.RandomState()
rng.seed(seed)
return rng
| ContextualBO-main | park_abr/park/utils/seeding.py |
import os
def create_folder_if_not_exists(folder_path):
if not os.path.exists(folder_path):
os.makedirs(folder_path)
| ContextualBO-main | park_abr/park/utils/misc.py |
import networkx as nx
import numpy as np
class DirectedGraph(object):
def __init__(self, node_features=None, edge_features=None):
self.graph = nx.DiGraph()
if node_features is not None:
self.update_nodes(node_features)
if edge_features is not None:
self.update_edges... | ContextualBO-main | park_abr/park/utils/directed_graph.py |
def print_red(s):
print("\033[91m" + s + "\033[0m")
def print_orange(s):
print("\033[93m" + s + "\033[0m")
def print_green(s):
print("\033[92m" + s + "\033[0m")
def print_blue(s):
print("\034[92m" + s + "\033[0m")
| ContextualBO-main | park_abr/park/utils/colorful_print.py |
ContextualBO-main | park_abr/park/utils/__init__.py | |
from collections import OrderedDict
class OrderedSet(object):
def __init__(self, contents=()):
self.set = OrderedDict((c, None) for c in contents)
def __contains__(self, item):
return item in self.set
def __iter__(self):
return iter(self.set.keys())
def __len__(self):
... | ContextualBO-main | park_abr/park/utils/ordered_set.py |
# Format follows OpenAI gym https://gym.openai.com
# Folk of the adaptive video streaming environment in https://github.com/park-project/park
def load(entry_point):
import pkg_resources # takes ~400ms to load, so we import it lazily
entry_point = pkg_resources.EntryPoint.parse("x={}".format(entry_point))
... | ContextualBO-main | park_abr/park/envs/registration.py |
# Format follows OpenAI gym https://gym.openai.com
# Folk of the adaptive video streaming environment in https://github.com/park-project/park
from park.envs.registration import make, register
register(env_id="abr_sim_fb", entry_point="park.envs.abr_sim:ABRSimFBEnv")
| ContextualBO-main | park_abr/park/envs/__init__.py |
# Folk of the adaptive video streaming environment in https://github.com/park-project/park
from collections import deque
import numpy as np
from ax.utils.common.logger import get_logger
from park import core, logger, spaces
from park.envs.abr_sim.trace_loader import (
get_chunk_time,
load_chunk_sizes,
loa... | ContextualBO-main | park_abr/park/envs/abr_sim/abr.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# A modification of the adaptive video streaming environment in https://github.com/park-project/park
from park.envs.abr_sim.abr_fb import ABRS... | ContextualBO-main | park_abr/park/envs/abr_sim/__init__.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# A modification of the adaptive video streaming environment in https://github.com/park-project/park
from collections import deque
import num... | ContextualBO-main | park_abr/park/envs/abr_sim/abr_fb.py |
# Folk of the adaptive video streaming environment in https://github.com/park-project/park
import os
import numpy as np
import park
def get_chunk_time(trace, t_idx):
if t_idx == len(trace[0]) - 1:
return 1 # bandwidth last for 1 second
else:
return trace[0][t_idx + 1] - trace[0][t_idx]
de... | ContextualBO-main | park_abr/park/envs/abr_sim/trace_loader.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# A modification of the adaptive video streaming environment in https://github.com/park-project/park
import json
import park
def get_chunk_... | ContextualBO-main | park_abr/park/envs/abr_sim/fb_trace_loader.py |
#! /usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import json
import numpy as np
from ax.modelbridge.factory import get_GPEI, get_sobol
from ax.modelbridge.generation_... | ContextualBO-main | benchmarks/run_synthetic_benchmarks_agg_reward.py |
#! /usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import datetime
import json
from typing import Any, Dict, List, Optional
import numpy as np
from ax.core.parameter im... | ContextualBO-main | benchmarks/run_synthetic_benchmarks_multioutput_reward.py |
#! /usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
from abc import ABC
from typing import Dict, List
import numpy as np
import torch
from ax.models.random.s... | ContextualBO-main | benchmarks/synthetic_problems.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Any, Dict, Optional
import numpy as np
from synthetic_problems import (
Branin1DEmbedding,
Branin2DBase,
Hartm... | ContextualBO-main | benchmarks/get_synthetic_problem.py |
#! /usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Any, Dict, List, Optional, Type
import torch
from ax.core.data import Data
from ax.core.experiment... | ContextualBO-main | benchmarks/cbo_generation_strategy.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
from scipy.spatial.transform import Rotation as R
import os
from glob import glob
from tqdm import tqdm
import scipy.io as sio
i... | 3D-Vision-and-Touch-main | data_loaders.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import numpy as np
import torch
import time
import sys
sys.path.insert(0, "../")
from pytorch3d.loss import chamfer_distance as c... | 3D-Vision-and-Touch-main | utils.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import numpy as np
import os
from tqdm import tqdm
interval = 1300
commands_to_run = []
for i in range(200):
commands_to_run ... | 3D-Vision-and-Touch-main | touch_charts/submit.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import os
import submitit
import argparse
import produce_sheets
parser = argparse.ArgumentParser()
parser.add_argument('--seed... | 3D-Vision-and-Touch-main | touch_charts/runner.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import torch.nn as nn
import torch
import torch.nn.functional as F
# implemented from:
# https://github.com/MicrosoftLearning/d... | 3D-Vision-and-Touch-main | touch_charts/models.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import models
import os
import torch
import numpy as np
import torch.optim as optim
from torch.utils.data import DataLoader
from... | 3D-Vision-and-Touch-main | touch_charts/produce_sheets.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import models
from torch.utils.tensorboard import SummaryWriter
import torch
import numpy as np
import torch.optim as optim
impo... | 3D-Vision-and-Touch-main | touch_charts/recon.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
from .chamfer_distance import ChamferDistance
| 3D-Vision-and-Touch-main | third_party_code/__init__.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import torch
from torch.utils.cpp_extension import load
cd = load(name="cd",
sources=["../third_party_code/chamfer_dist... | 3D-Vision-and-Touch-main | third_party_code/chamfer_distance.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import numpy as np
import os
from tqdm import tqdm
def call(command):
os.system(command)
param_namer = {'--seed': 'seed', '--n... | 3D-Vision-and-Touch-main | vision_charts/submit.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import os
import submitit
import argparse
import recon
parser = argparse.ArgumentParser()
parser.add_argument('--seed', type=i... | 3D-Vision-and-Touch-main | vision_charts/runner.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import torch.nn as nn
import torch
import numpy as np
from torch.nn.parameter import Parameter
import torch.nn.functional as F
i... | 3D-Vision-and-Touch-main | vision_charts/models.py |
#Copyright (c) Facebook, Inc. and its affiliates.
#All rights reserved.
#This source code is licensed under the license found in the
#LICENSE file in the root directory of this source tree.
import os
import models
import numpy as np
import torch
from torch.utils.data import DataLoader
from torch.autograd import Vari... | 3D-Vision-and-Touch-main | vision_charts/recon.py |
# coding=UTF8
import json
import re
import sys
import fileinput
control_chars = ''.join(map(unichr, range(0,32) + range(127,160)))
control_char_re = re.compile('[%s]' % re.escape(control_chars))
def remove_control_chars(s):
return control_char_re.sub('', s)
def convert():
# try:
# fin = open(FILE)
... | elementary-master | test/generate_json.py |
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "elementary.settings.dev")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
| elementary-master | django/manage.py |
from django.conf import settings
from django.db import models
from pymongo import MongoClient
# placeholder for refreshing elasticsearch when documents
# are updated. currently, documents are inserted into elasticsearch when
# dd pipeline is run.
class ElasticMixin(models.Model):
def update_elastic_data(self, da... | elementary-master | django/resources/model_mixins.py |
from __future__ import absolute_import
from collections import defaultdict
import logging
import os
from celery import shared_task
from django.conf import settings
from django.db import IntegrityError
from django.db.models import F
from django.utils.timezone import now
from pymongo import MongoClient, UpdateOne
from... | elementary-master | django/resources/tasks.py |
import io
import json
import logging
from multiprocessing.pool import ThreadPool
import os
import zipfile
from binaryornot.check import is_binary
from django.conf import settings
import requests
logger = logging.getLogger(__name__)
def download_file(url, local_path):
'''Returns None if successful; otherwise err... | elementary-master | django/resources/dataio.py |
from django.db import models
from django.contrib.postgres.fields import ArrayField, HStoreField
from django.utils.http import urlquote
from .model_mixins import MongoMixin, ElasticMixin
import uuid
class Repository(models.Model):
PIPELINE_CHOICES = (
('memex/atf', 'Memex ATF'),
('memex/escort', '... | elementary-master | django/resources/models.py |
from functools import wraps
from django.contrib.auth.models import User
from django.db import IntegrityError
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from .models import Document, DocSource, Repository
from .tasks import process_docs_queue, ingest_sources_queue
imp... | elementary-master | django/resources/serializers.py |
elementary-master | django/resources/__init__.py | |
from django.test import TestCase
from django.contrib.auth.models import User
from models import Repository
from models import Document
# Create your tests here.
class UserTestCase(TestCase):
def test_create_remove(self):
# Create a user
user1 = User.objects.create_user('john', 'lennon@thebeatles... | elementary-master | django/resources/tests.py |
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import Http404, HttpResponse
from django.shortcuts import render, get_object_or_404
from rest_framework import generics, mixins, viewsets
from rest_framework.authtoken.... | elementary-master | django/resources/views.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import uuid
def gen_uuid(apps, schema_editor):
MyModel = apps.get_model('resources', 'DocSource')
for row in MyModel.objects.all():
row.crawlid = uuid.uuid4()
row.save()
class Migration(mi... | elementary-master | django/resources/migrations/0009_auto_20150707_2322.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('resources', '0003_auto_20150526_1530'),
]
operations = [
migrations.AddField(
model_name='result',
n... | elementary-master | django/resources/migrations/0004_result_record_type.py |
elementary-master | django/resources/migrations/__init__.py | |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('resources', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Mention',
fields=[
... | elementary-master | django/resources/migrations/0002_auto_20150525_2317.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import resources.models
class Migration(migrations.Migration):
dependencies = [
('resources', '0007_document_processing_error'),
]
operations = [
migrations.AddField(
mod... | elementary-master | django/resources/migrations/0008_auto_20150707_2308.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('resources', '0002_auto_20150525_2317'),
]
operations = [
migrations.CreateModel(
name='Result',
fiel... | elementary-master | django/resources/migrations/0003_auto_20150526_1530.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('resources', '0005_add_doc_sources'),
]
operations = [
migrations.AlterField(
model_name='repository',
... | elementary-master | django/resources/migrations/0006_auto_20150604_0124.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import resources.models
class Migration(migrations.Migration):
dependencies = [
('resources', '0009_auto_20150707_2322'),
]
operations = [
migrations.AlterField(
model_nam... | elementary-master | django/resources/migrations/0010_auto_20150707_2322.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
import django.contrib.postgres.fields.hstore
from django.contrib.postgres.operations import HStoreExtension
class Migration(migrations.Migration):
dependencies = [
mi... | elementary-master | django/resources/migrations/0001_initial.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('resources', '0004_result_record_type'),
... | elementary-master | django/resources/migrations/0005_add_doc_sources.py |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('resources', '0006_auto_20150604_0124'),
]
operations = [
migrations.AddField(
model_name='document',
... | elementary-master | django/resources/migrations/0007_document_processing_error.py |
# -*- coding: utf-8 -*-
import codecs
import errno
import io
import json
import logging
import multiprocessing
import os
import shutil
import sys
from subprocess import Popen
from resources.dataio import parse_docs
logger = logging.getLogger(__name__)
# tmp dir with respect to elementary root
TMP_DIR = 'tmp'
NUM_CO... | elementary-master | django/ddctrl/ddctrl.py |
elementary-master | django/ddctrl/__init__.py | |
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
| elementary-master | django/elementary/__init__.py |
from __future__ import absolute_import
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'elementary.settings.prod')
from django.conf import settings
app = Celery('elementary')
# Using a string here means the work... | elementary-master | django/elementary/celery.py |
from django.conf.urls import include, url
from rest_framework import routers
from resources import views
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'repos', views.RepoViewSet)
router.register(r'docs/(?P<user>\w+)/(?P<repo>\w+)', views.DocViewSet)
router.register(r's... | elementary-master | django/elementary/urls.py |
# Fix kombu incompatibility with pymongo 3.0
# https://github.com/celery/kombu/pull/479/files
from kombu.transport.mongodb import Channel, BroadcastCursor
from pymongo import MongoClient
from pymongo.cursor import CursorType
from kombu.syn import _detect_environment
def _kombu_mongo_open(self, scheme='mongodb://'):... | elementary-master | django/elementary/hacks.py |
"""
WSGI config for elementary project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SE... | elementary-master | django/elementary/wsgi.py |
import logging
class ExceptionLoggingMiddleware(object):
def process_exception(self, request, exception):
logging.exception('Exception handling request for ' + request.path)
| elementary-master | django/elementary/middleware/exception_log.py |
elementary-master | django/elementary/middleware/__init__.py | |
import copy
import time
from django.conf import settings
from django.utils.timezone import now
from pymongo import MongoClient
REQUEST_META_FIELDS = [
'HTTP_REFERER',
'HTTP_USER_AGENT',
'HTTP_ACCEPT_LANGUAGE',
'REMOTE_ADDR',
'REMOTE_HOST',
'REQUEST_METHOD',
'QUERY_STRING',
]
class Reque... | elementary-master | django/elementary/middleware/request_log.py |
elementary-master | django/elementary/settings/__init__.py | |
from base import *
DEBUG = True
LOGGING['root']['level'] = 'DEBUG'
try:
from .dev_local import *
except:
pass
| elementary-master | django/elementary/settings/dev.py |
from base import *
try:
from .prod_local import *
except:
pass
# we currently don't have an interface that allows an administrator
# to create a repository for another user. Until we have added this
# capability, allow users to create repos.
ELEMENTARY_ALLOW_REPO_CREATION = True
| elementary-master | django/elementary/settings/prod.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.