Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine Spec-z Catalogs and Training Set Maker page #219

Merged
merged 19 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/core/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from core.views.pipeline import PipelineViewSet
from core.views.process import ProcessViewSet
from core.views.product import ProductViewSet
from core.views.product import ProductSpeczViewSet
from core.views.product_content import ProductContentViewSet
from core.views.product_file import ProductFileViewSet
from core.views.product_type import ProductTypeViewSet
Expand Down
29 changes: 27 additions & 2 deletions backend/core/views/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,40 @@ def filter_name(self, queryset, name, value):
return queryset.filter(query)

def filter_type_name(self, queryset, name, value):
query = format_query_to_char(name, value, ["product_type__display_name", "product_type__name"])
query = format_query_to_char(
name, value, ["product_type__display_name", "product_type__name"]
)

return queryset.filter(query)

def filter_release(self, queryset, name, value):
query = format_query_to_char(name, value, ["release__display_name", "release__name"])
query = format_query_to_char(
name, value, ["release__display_name", "release__name"]
)
return queryset.filter(query)


class ProductSpeczViewSet(viewsets.ReadOnlyModelViewSet):
"""Esse endpoint retorna apenas os produtos cujo o product type é = a 'spec-z' e o status é = a 1"""

queryset = Product.objects.filter(product_type__name="specz_catalog", status=1)
serializer_class = ProductSerializer
search_fields = [
"display_name",
"user__username",
"user__first_name",
"user__last_name",
]
filterset_class = ProductFilter
ordering_fields = [
"id",
"display_name",
"product_type",
"created_at",
]
ordering = ["-created_at"]


class ProductViewSet(viewsets.ModelViewSet):
queryset = Product.objects.all()
serializer_class = ProductSerializer
Expand Down
3 changes: 3 additions & 0 deletions backend/pzserver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@

UPLOAD_DIR = os.getenv("UPLOAD_DIR", MEDIA_URL)

# Criando VA APPEND
APPEND_SLASH=False

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

Expand Down
3 changes: 2 additions & 1 deletion backend/pzserver/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
OrchestrationInfoView, OrchestrationPipelinesView,
PipelineViewSet, ProcessViewSet, ProductContentViewSet,
ProductFileViewSet, ProductTypeViewSet, ProductViewSet,
ReleaseViewSet, UserViewSet)
ProductSpeczViewSet, ReleaseViewSet, UserViewSet)
from django.conf import settings

from django.contrib import admin
Expand All @@ -33,6 +33,7 @@
route.register(r"releases", ReleaseViewSet, basename="releases")
route.register(r"product-types", ProductTypeViewSet, basename="product_types")
route.register(r"products", ProductViewSet, basename="products")
route.register(r"products-specz", ProductSpeczViewSet, basename="products_specz")
route.register(r"product-contents", ProductContentViewSet, basename="product_contents")
route.register(r"product-files", ProductFileViewSet, basename="product_files")

Expand Down
53 changes: 53 additions & 0 deletions frontend/components/EmailField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// import React, { useState, useEffect } from 'react'
// import TextField from '@mui/material/TextField'
// import PropTypes from 'prop-types'

// function EmailField({ initialValue = '', onEmailChange, onClearForm }) {
// const [email, setEmail] = useState(initialValue)
// const [isValidEmail, setIsValidEmail] = useState(true)

// const handleEmailChange = event => {
// const newEmail = event.target.value
// setEmail(newEmail)
// onEmailChange(newEmail)
// }

// const handleBlur = () => {
// if (email.trim() !== '') {
// validateEmail(email)
// }
// }

// const validateEmail = value => {
// const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
// const isValid = emailRegex.test(value)
// setIsValidEmail(isValid)
// }

// useEffect(() => {
// setEmail(initialValue)
// setIsValidEmail(true)
// }, [onClearForm, initialValue])

// return (
// <div>
// <TextField
// id="email"
// variant="outlined"
// value={email}
// onChange={handleEmailChange}
// onBlur={handleBlur}
// error={!isValidEmail}
// helperText={!isValidEmail ? 'Invalid email address' : ''}
// />
// </div>
// )
// }

// EmailField.propTypes = {
// initialValue: PropTypes.string,
// onEmailChange: PropTypes.func,
// onClearForm: PropTypes.func
// }

// export default EmailField
36 changes: 36 additions & 0 deletions frontend/components/NNeighbors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useState, useEffect } from 'react'
import TextField from '@mui/material/TextField'
import PropTypes from 'prop-types'

const NNeighbors = ({ nNeighbors, onChange }) => {
const [localNNeighbors, setLocalNNeighbors] = useState(nNeighbors)

useEffect(() => {
setLocalNNeighbors(nNeighbors)
}, [nNeighbors])

const handleNeighborsChange = event => {
const inputValue = event.target.value.replace(/[^\d]/g, '')
const newValue = parseInt(inputValue, 10) || 1
setLocalNNeighbors(newValue)
onChange(newValue)
}

return (
<TextField
id="nNeighbors"
variant="outlined"
value={localNNeighbors}
onChange={handleNeighborsChange}
inputProps={{ inputMode: 'numeric', pattern: '[0-9]*', min: 1, step: 1 }}
/>
)
}

NNeighbors.propTypes = {
nNeighbors: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
.isRequired,
onChange: PropTypes.func.isRequired
}

export default NNeighbors
2 changes: 1 addition & 1 deletion frontend/components/ReleaseSelect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import MenuItem from '@mui/material/MenuItem'
import { getReleases } from '../services/product'
import { getReleases } from '../services/release'
import { TextField } from '@mui/material'

// export default function ReleaseSelect({ value, onChange, disabled }) {
Expand Down
30 changes: 30 additions & 0 deletions frontend/components/SearchRadius.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import TextField from '@mui/material/TextField'
import PropTypes from 'prop-types'
import React from 'react'

function SearchRadius({ searchRadius, onChange }) {
const formattedRadius = searchRadius.toLocaleString('en-US', {
minimumFractionDigits: 1,
maximumFractionDigits: 1
})

const handleRadiusChange = event => {
onChange(parseFloat(event.target.value))
}

return (
<TextField
type="number"
value={formattedRadius}
onChange={handleRadiusChange}
inputProps={{ min: 0, max: 90, step: 0.1 }}
/>
)
}

SearchRadius.propTypes = {
searchRadius: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired
}

export default SearchRadius
82 changes: 47 additions & 35 deletions frontend/components/SpeczData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as React from 'react'
import { getProducts } from '../services/product'
import { DataGrid } from '@mui/x-data-grid'
import moment from 'moment'
import { Box } from '@mui/material'
Expand Down Expand Up @@ -30,13 +32,29 @@ const columns = [
}
]

async function fetchData(filters, query) {
try {
const response = await getProducts({
filters,
page: 0,
page_size: 25,
sort: [{ field: 'created_at', sort: 'desc' }],
search: query
})

return response.results
} catch (error) {
console.error(error)
throw error
}
}

function DataTable({ rows }) {
return (
<Box style={{ height: 300, width: '100%' }}>
<Box sx={{ height: 300, width: '100%' }}>
<DataGrid
rows={rows}
columns={columns}
// getRowId={row => row.id}
pageSizeOptions={[5, 10]}
checkboxSelection
/>
Expand All @@ -48,39 +66,33 @@ DataTable.propTypes = {
rows: PropTypes.arrayOf(PropTypes.object).isRequired
}

const rows = [
{
id: 1,
display_name: 'Jandson 1',
uploaded_by: 'User1',
created_at: '2023-01-01'
},
{
id: 2,
display_name: 'Jandson 2',
uploaded_by: 'User2',
created_at: '2023-02-15'
},
{
id: 3,
display_name: 'Jandson 3',
uploaded_by: 'User3',
created_at: '2023-03-22'
},
{
id: 4,
display_name: 'Jandson V',
uploaded_by: 'User1',
created_at: '2023-04-10'
},
{
id: 5,
display_name: 'Jandson Try',
uploaded_by: 'User2',
created_at: '2023-05-05'
}
]
function DataTableWrapper({ filters, query }) {
const [rows, setRows] = React.useState([])

React.useEffect(() => {
const fetchAndSetData = async () => {
try {
const data = await fetchData(filters, query)
setRows(data)
} catch (error) {
console.error(error)
}
}

fetchAndSetData()
}, [filters, query])

export default function App() {
return <DataTable rows={rows} />
}

DataTableWrapper.propTypes = {
filters: PropTypes.object,
query: PropTypes.string
}

DataTableWrapper.defaultProps = {
filters: {},
query: ''
}

export default DataTableWrapper
Loading
Loading